zachary Posted May 12, 2006 Share Posted May 12, 2006 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 More sharing options...
skym Posted May 12, 2006 Share Posted May 12, 2006 I usually use the script found at http://www.dynamicdrive.com/dynamicindex16/requiredcheck.htmIt needs to know which fields are mandatory, but you can get inspired and make your own if there are too many fields in the form. Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 12, 2006 Share Posted May 12, 2006 You do mean only one form that contains various fields do you? Or do you mean many forms with various content? The last one is not very logical, is it? Link to comment Share on other sites More sharing options...
aspnetguy Posted May 12, 2006 Share Posted May 12, 2006 I am pretty sure he means one form where all the fields are required. Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 12, 2006 Share Posted May 12, 2006 (edited) 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 ofdocument.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 May 12, 2006 by Dan The Prof Link to comment Share on other sites More sharing options...
scott100 Posted May 12, 2006 Share Posted May 12, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now