Is there some kind of way I can have:
onSubmit="return function('check every variable in the form')"
And then in the head have something like:
function function(contents) {
if (((contents / contents) != 1) && (contents != 0)) {
alert('Please enter only a number into this box \n (No commas or decimals)');
return false;
} else {
return true;
}
}
Thanks for the help!
php variables with Javascript
Moderator: General Moderators
Make the function that validates form fields. Then set the value of the onSubmit attribute to the name of the validating function.
So you'd setup the function:
And then setup the onSubmit attribute of the form:
So you'd setup the function:
Code: Select all
<script language="javascript">
function validate_elements() {
// code to validate elements
}
</script>OK, so right now I have this:
But it does not work. I think because of how I have the variables, but not really sure how to do that and not sure where to go to have some good help on it.
Code: Select all
<head><SCRIPT LANGUAGE="JAVASCRIPT"><!--
function check(thing) {
if (((document.thing.value / document.thing.value) != 1) && (document.thing.value != 0)) {
alert('Please enter only a number into this box \n (No commas or decimals)');
return false;
} else {
return true;
}
}
//--></SCRIPT></head>
<form name ="myform" method="post" action ="question2.html" onSubmit="return check(how_many);">
<p>How many years do you plan to be in your home?</p>
<p><input type="text" name="how_many" size="10"></p>
<input type="hidden" name="passer">
<input type="submit" value="Next" name="submit">
</form>