peddel Posted September 19, 2008 Share Posted September 19, 2008 Well i got this form that has a variable amount of fields depending on what the user did in previous forms. Thing is i now want to submit this form ONLY when all fields are filled in. Is there a way to check all available form fields one by one without knowing the exact ID/name of that field. So i can run trough the fields and just check if its filled or not, as long as its not filled i send a false. When all fields are filled ill send a true. I used some php to scroll trough the cells to send the info to some variables using this code, maybe there's some code existing in javascript that does the same? foreach ($_POST as $fld => $val) { unset($_SESSION[$fld]); $_SESSION[$fld] = $val; } Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted September 19, 2008 Share Posted September 19, 2008 If you give your form tag an ID, like so: <form id="form1" method="post" action=""> Then you can use some javascript like so: function checkFields(){ var fields = document.getElementById("form1").elements; for(var i = 0; i < fields.length; i++){ if(fields[i].value == ''){ return false; } } return true; } Quote Link to comment Share on other sites More sharing options...
peddel Posted September 19, 2008 Author Share Posted September 19, 2008 Thx for solving my problem =) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.