Jump to content

Is there a


zachary

Recommended Posts

Im making a form were All the forms are nessery. I need a script that wont allowany forms to be left blank. So it should make a pop-up saying:"We are sorry but you must fill in all the forms.".

Link to comment
Share on other sites

Naturally, but well, Then he said it a little oddly, but whatever .In the tutorials you should be able to find some things you like, like using inside script functions:

with (document.forms["something"]) { somefield.value = "something" }
instead of
document.forms["something"].elements["somefield"].value = "something"
(for each element)This for example, would really help you checking the value of those fields. Not to mention the ereg("",$field) in PHP :) Edited by Dan The Prof
Link to comment
Share on other sites

Here you go, this should make more sense :) All you need to do is add however many <input>'s to the form and javascript will automatically detect them, you will not need to alter any of the javascript :)

<html><head><title></title><script>function check_fields(){var total=0;var complete=true;var formLength=document.myform.elements.length;formLength=formLength-2; //ignores submit and reset buttonsalert("Checking "+formLength+ " fields");for(i=0;i<formLength;i++) {   val=document.myform.elements[i].value;   if((val=="")||(val==null)){total+=1}; } if(total>0) {   alert("You have failed to complete "+total+" fields");   complete=false; }return complete;}</script></head><body><form name='myform' onsubmit="return check_fields()" action="process.php"><input type="text"><br/ ><input type="text"><br/ ><input type="text"><br/ ><input type="text"><br/ ><input type="text"><br/ ><input type="text"><br/ ><textarea></textarea><br/ ><input type="text"><br/ ><input type="text"><br/ ><!--      You can add as many fields as you want without having to     update the javascript --><input name="submit" type="submit" value='submit'><input name="reset" type=reset value='clear'></form></body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...