感谢任何人的帮助......下面的PHP包含一个txt文件中的项目列表,每个项目旁边是一个文本框供用户输入数量,默认设置为1。我正在尝试清除用户单击文本框时的框,有什么想法吗?
<input type='text' id='qty' name='$partno' size='1' value='0'>
到目前为止,我已经尝试过使用 JavaScript,但没有运气。
<script>
function validateName()
{
var x=document.forms["purchase"]["visitor"].value;
if (x==null || x=="")
{
alert("Visitor name must be entered");
return false;
}
}
function name()
{
document.getElementById('qty').value = "";
}
</script>
</head>
<body>
<h1>Items Available</h1>
<form id="purchase" name="purchase" action="confirm.php" method="post" onsubmit="return validateName()">
<table>
<h3>Visitor Name: <input type='text' name='visitor'></h3>
<tr><th></th><th></th><th></th><th>Price</th><th>QTY</th></tr>
<?php
if (!($data = file('items.txt'))) {
echo 'ERROR: Failed to open file! </body></html>';
exit;
}
foreach ($data as $thedata) {
list($partno, $name, $description, $price, $image) = explode('|', $thedata);
echo "<tr><td><img src='$image' width='60' height='60' alt='image'></td><td><h3>$name</h3></td><td> $description</td>
<td> <b>£$price</b></td><td><input type='text' id='qty' name='$partno' size='1' value='0'></td></tr>";
//<input type='text' size='1' name='partno_qty' value='1'</td>
}
?>
</table>
<input type="submit" value="Purchase">
<input type="reset" value="Clear">
</form>