<html>
<head>
</head>
<body>
<p>Exercise 5-3</p>
<script type = "text/javascript">
function sub()
{ sumit = true
var fir = document.getElementById("first")
var fir1 = Number(fir);
alert(fir.value)
if (fir.isNaN)
{
alert("bad");
sumit = false;
}
var sec = document.getElementById("second")
var sec1 = Number(sec);
if (sec.isNaN)
{
alert("bad");
sumit = false;
}
var thir = document.getElementById("third")
var thir1 = Number(thir);
if (thir.isNaN)
{
alert("bad");
sumit = false;
}
var x = document.getElementById("x")
var y = document.getElementById("y")
var z = document.getElementById("z")
return sumit;
}
</script>
<form name = "f1" onsubmit="return sub()"action = "http://earl.rodd.us/dispform.php">
<p>
<table border>
<tr><td>Price</td><td>quantity</td></tr>
<tr><td>4.56</td><td><input type = "text" name = "first" size = "10" value = 0></td></tr>
<tr><td>8.98</td><td><input type = "text" name = "second" size = "10" value = 0></td></tr>
<tr><td>14.16</td><td><input type = "text" name = "third" size = "10" value = 0></td></tr>
</table>
<input type = "reset" id = "reset" />
<input type = "submit" id = "sumit" />
<input type = "hidden" name = "x" value = "4.56">
<input type = "hidden" name = "y" value = "8.98">
<input type = "hidden" name = "z" value = "14.16">
</form>
</body>
This is what I have so far. It's supposed to display an alert if there is not a numeric value submitted into the form fields after the submit button is pushed. I cannot figure out how to put the first quantity field into focus. If there is an error, the focus needs to be in the field where the error occurred. I've tried looking through my web programming book and online googling but no luck.

New Topic/Question
Reply



MultiQuote




|