<分区>
Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”
我希望当我在选择框中选择某个值时多次显示一个字符串,例如,如果我选择值 2,它将显示一个字符串两次。
这是我试过的代码:
<!DOCTYPE HTML>
<html>
<head>
<script>
function checkIt()
{
var getNum = document.getElementById("numb").value;
//this_file.php ... im specifying for just. you specify this full code in any of file and specify the whole url path
location.href="this_file.php?countIt="+getNum;
}
</script>
<style type="text/css">
.centrer
{
position: absolute;
left: 50%;
top: 50%;
font-size:24px;
}
</style>
</head>
<body>
<select name="nombres" id="numb" onchange="checkIt();">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<?php
if($_REQUEST["countIt"])
{
$displayTimes = $_REQUEST["countIt"];
}
?>
<div class="centrer">
<?php
$s = "Hello World! <br/>";
for($i=0; $i<$displayTimes; $i++)
echo $s;
?>
</div>
</body>
</html>
但是我有一个问题:
Notice: Undefined variable: displayTimes in C:\Program Files\EasyPHP-12.1\www\site\Untitled-1.php on line 43
注意第 43 行是:for($i=0; $i<$displayTimes; $i++)
还有另一个问题,当我选择“1”值时,它会执行任何操作,而且当我选择其他值时,选择框中的选定值仍然是值“1”,我还有一个问题是没有仅通过使用 PHP 而无需使用 JS 的其他方法?