This is just a little js that I was working on to make a form check more portable.
To use it all you need to do is have id’s on your form fields and then for the required ones have this in the <form> tag
onsubmit=“return check_form(’formname’,'Title|Date|Name’)”
where ‘formname’ is the name of the form and the id’s you want to check are a listed separated by a |
and using the js
<script type=“text/javascript” /> // Function to grab inputs from specified fields by ID // and check to see if they are blank and alert user if they are function check_form(formname,ids) { var alert_str=”; var idarray = ids.split("|"); for(var i=0;i var fieldvalue = document.getElementById(idarray[i]).value; if(fieldvalue ==”){ alert_str += idarray[i] + " is required\n"; // colour the field to help user document.getElementById(idarray[i]).style.backgroundColor = "#FACADE"; } else { // colour the field back to default -change if not white document.getElementById(idarray[i]).style.backgroundColor = "#FFFFFF"; } } if(alert_str ==”){ eval("document."+formname+".submit()"); } else { alert(alert_str); return false; } // <script />
It doesn’t tell you if the input is valid though just if it exists or not