Would appreciate any help from anyone... the below PHP contains a list of items from a txt file, next to each item is a text box for the user to enter the qty, by default set to 1. I'm trying to clear the box when the user clicks on a text box, any ideas?
<input type='text' id='qty' name='$partno' size='1' value='0'>
So far I've tried using JavaScript but had no luck.
<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>