...

View Full Version : Validation



dips_007
03-22-2004, 08:09 PM
I can not get this code to work it does not seem to do any thing.
I aint sure what the problem is

<html>
<head>
<title>Route Planner</title>

<script language="JavaScript" type="text/JavaScript">

function validateNumber(b) {
var n = b.value*1;
return (n >= 1 && n <= 3);
}

function validateTime(b) {
var t = b.value;
var t_array = t.split(".");

var hour = t_array[0]*1;
var mins = t_array[1]*1;

return(hour >= 0 && hour <= 23 && mins >= 0 && mins <= 59);
}

function validateBoxes() {
if(!validateNumber(numBox)) {
alert("Bad Number");
}

if(!validateTime(timeBox)) {
alert("Bad Time");
}
}

</script>
</head>
<body>

<form>
<input type="text" name="numBox" id="numBox"/>
<input type="text" name="timeBox" id="timeBox"/>
<input name="button" type=button onClick="validateBoxes"/>
</form>

</body>
</html>

Roy Sinclair
03-22-2004, 08:41 PM
Bad call of the function:



<input name="button" type=button onClick="validateBoxes()"/>


Of course once you fix that you'll find that the validateBoxes function is also broken:



function validateBoxes() {
if(!validateNumber(document.getElementById('numBox'))) {
alert("Bad Number");
}

if(!validateTime((document.getElementById('timeBox'))) {
alert("Bad Time");
}
}

dips_007
03-22-2004, 08:54 PM
it still dont work i dont know what is wrong

<html>
<head>
<title>Route Planner</title>

<script language="JavaScript" type="text/JavaScript">

function validateNumber(b) {
var n = b.value*1;
return (n >= 1 && n <= 3);
}

function validateTime(b) {
var t = b.value;
var t_array = t.split(".");

var hour = t_array[0]*1;
var mins = t_array[1]*1;

return(hour >= 0 && hour <= 23 && mins >= 0 && mins <= 59);
}

function validateBoxes() {
if(!validateNumber(document.getElementById('numBox')) {
alert("Bad Number");
}

if(!validateTime(document.getElementById('timeBox')) {
alert("Bad Time");
}
}

</script>
</head>
<body>
<p>

<form>
<input type="text" name="numBox" id="numBox"/>
<input type="text" name="timeBox" id="timeBox"/>
<input name="button" type=button onClick="validateBoxes()"/>
</form>

</body>
</html>

Roy Sinclair
03-22-2004, 09:05 PM
You left off one ")" character in each of those modified lines in your validateBoxes function. You have three "(" characters but only two ")" which is obviously invalid.

Do this, On the IE Menu bar: "Tools > Internet Options > Advanced", check the box labeled "Display a notification about every script error".

If you're working with scripts it's pretty much mandatory that you be informed about script errors so you'll know they exist and can hunt them down. Otherwise you get a tiny little icon on the status bar telling you there was a problem and that icon is pretty easy to miss.

dips_007
03-22-2004, 09:09 PM
thanks for your time that solved my problem
took ur advice enableded the debugger

fredmv
03-22-2004, 09:29 PM
Originally posted by dips_007
enableded the debugger If you'd even call it that. I don't particularly find random or otherwise inaccurate error messages helpful. :rolleyes:

What you actually want to do is get yourself a real browser (http://www.mozilla.org/) and take advantage of its excellent JavaScript debugging tools (among other things) such as the JavaScript console, and of course the complete JavaScript debugging enviorment: Venkman.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum