Forum Moderators: open
I am basically teaching myself JavaScript from all the useful websites i can find.
My latest project is to introduce form verification. I have a page of inputs which are parameters for an image simulator. I just want to check simple things whether the data entered is within certain boundaries etc etc...
Unfortunately whatever i do the form submits without checking! (n.B this is all "offline" stuff at the moment)
I would appreciate some help, or pointers where i am going wrong.
Thanks
___________________________________________________________
here is the code for the JavaScript:
___________________________________________________________
<html>
<head>
<title>
MSSL ::: GAIA IMAGE SIMULATION - Parameter Input </title>
[code]
<script language="JavaScript">
//form verification
function checkform(oForm) {
if((oForm.xpixels < 500) ¦¦ oForm.xpixels > 1010)) {
alert("Number of xpixels is not within boundary");
return.false;
}
else {
return.true ;
}
}
</script>
</head>
<form name="form" onSubmit = "return checkform(this)"
action="thankyou.html" method="post">
and the input:
____________________________________________________________
<!-- NUMBER TWO INPUT -->
<tr>
<td valign="middle">
<font size="3">2. Number of X pixels:   </font>
<input size="4" type = "text" name="xpixels"
value="1000" maxlength='4'>
</input>
 
 
</td>
<td border="0" valign="middle" align = "right">
<input type="button" value="Help" name="button3"
target="new" onClick="Start('xpixel.html')"
onMouseover="window.status='Explanation for
parameter 2'; return true"
onMouseout="window.status=' '; return true">
</td>
and the submit button:
___________________________________________________________
<td align="center">
<input type ="submit" value="Start Program">
</input>
 
 
<input type = "reset">
</input>
</td>
I am pretty sure i am just missing something silly. Either that,..or i am just not as clever as i think.
Lol,
Have a good day!
Thanks for the (quick) reply! I changed the return.false to return false, but the form still just jumps to the thankyou.html page that is set as "action".
What could be wrong?!
Interestingly enough i was browsing other forms and looking at their html sources. I got to this demo one and found that the page doesn't produce the alerts it should do on my machine:
Since you said that my script was working on your machine, is there any reason why it shouldn't on mine i.e no JavaScript support?!
Unfortunately i have another JavaScript code in the <head> tags that open new windows. This one does work:
<script language="JavaScript">
//JavaScript to open a pop-up window for "help"
function Start(page) {
OpenWin = this.open(page, "CtrlWindow","toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes,width=350,height=250");
}
</script>
The only other though that i have is that i have 17 other inputs on my form apart from the one listed in my first post. Is it possible an error in those could cause a problem with the JavaScript function even if they aren't being used by it. They are all based on the same script apart from two which are <select> based.
Thanks again
But no it still isn't working! AHHHHH
I separated the bits of the code that i posted on this site, from all the other stuff and put that into a new html file. I then used that, with the amendments and again it still just jumps to:
thankyou.html
as in the action="thankyou.html".
So it can't be any other faults...
Did anyone try the link i put above?! It would be useful to know if that form verification works for you guys, because it definitely doesn't for me! There could be a problem there!
I use a Unix system with Mozilla 1.0.1 (lol well basic)- stone-age almost.
Thanks peeps,
Duncs
If you are calling a form field, it should look like this: document.form1.fieldname.value > 1010
Did anyone try the link i put above?! It would be useful to know if that form verification works for you guys, because it definitely doesn't for me! There could be a problem there!
That form does not work for me, it gives errors.
nope it still not working...
It does seem to me like its not running the JavaScript properly. Do i need to make sure that the form input is a number before doing an if statement that looks at its magnitude.
I remember someone telling me about "parseField" or something like that. Do i need to pass all input values through that to make sure they are integers etc etc..
Duncs
I know you have to change the ¦¦ as its different on here than in my emacs text editor...
Nyhowz,..so the code works fine with you,..but the exact same code doesn't work with me?!
Thats WELL weird.
Wot does that tell us?! That it's something to do with my browser maybe...?
Duncs
<script language="JavaScript">
//form verification
function checkform() {
if (document.form1.xpixels.value < 500 ¦¦ document.form1.xpixels.value > 1010)
{
alert("Number of xpixels is not within boundary");
document.form1.xpixels.focus();
return (false);
}
return (true);
}
</script>
**************FORM******************
<form name="form1" onSubmit = "return checkform()" action="thankyou.html" method="post">
<!-- NUMBER TWO INPUT -->
<table width="311" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="259"> <font size="3">2. Number of X pixels:</font>
<input type="text" name="xpixels" size="4" maxlength="4" value="1000">
</td>
<td width="52">
<input type="button" value="Help" name="button3" target="new" onClick="Start('xpixel.html')"
onMouseOver="window.status='Explanation for parameter 2'; return true" onMouseOut="window.status=' '; return true">
</td>
</tr>
<tr>
<td width="259">
<input type="submit" name="Submit" value="Start Program" >
<input type="reset" name="Reset" value="Reset">
</td>
<td width="52"> </td>
</tr>
</table>
</form>
[Incase anybody ever has the same problem, finds this forum post etc etc]
It always bugs me when the solution isn't posted on the forum
<html>
<head>
<title> yiyiyiyiy</title>
<script language="JavaScript">
//form verification
function checkform() {
if (document.form1.xpixels.value < 500 ¦¦ document.form1.xpixels.value > 1010)
{
alert("Number of xpixels is not within boundary");
document.form1.xpixels.focus();
return (false);
}
return (true);
}
</script>
<script language="JavaScript">
//JavaScript to open a pop-up window for the help buttons
function Start(page) {
OpenWin = this.open(page, "CtrlWindow", "toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes,width=350,height=250");
}
</script>
</head>
<body>
<form name="form1" onSubmit = "return checkform()" action="thankyou.html" method="post">
<!-- NUMBER TWO INPUT -->
<table width="311" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="259"> <font size="3">2. Number of X pixels:</font>
<input type="text" name="xpixels" size="4" maxlength="4" value="1000">
</td>
<td width="52">
<input type="button" value="Help" name="button3" target="new" onClick="Start('xpixel.html')"
onMouseOver="window.status='Explanation for parameter 2'; return true" onMouseOut="window.status=' '; return true">
</td>
</tr>
<tr>
<td width="259">
<input type="submit" name="Submit" value="Start Program" >
<input type="reset" name="Reset" value="Reset">
</td>
<td width="52"> </td>
</tr>
</table>
</form>
</body>
</html>
onSubmit="return checkForm(this)"
and
function checkForm(oForm)
but instead of this:
oForm.xpixels
use this:
oForm.xpixels.value
The 'this' that you pass to checkForm is the same as your 'document.form1'. :)
I know this is a very late note to add on, but for any newbies reading, it's a little tip on object referencing. :)