dban00b
asked on
Javascript to catch bad form before submit
What code would I need for a javascript function checkform();
That would make sure:
"name" and "color" are not empty ie: obj.value!=""
If one of them IS empty, then show the div named "warning" and NOT submit the form
However if, they are both populated, then SUBMIT the form
Thanks!
That would make sure:
"name" and "color" are not empty ie: obj.value!=""
If one of them IS empty, then show the div named "warning" and NOT submit the form
However if, they are both populated, then SUBMIT the form
Thanks!
<form id="form1" name="form1" method="post" action="go.php">
<label>Your Name<input type="text" name="name" id="name" /></label>
Your Color:
<label><input type="radio" name="color" id="color" value="red" />Red</label>
<label><input type="radio" name="color" id="color" value="green" />Green</label>
<label><input type="radio" name="color" id="color" value="blue" />Blue</label>
<div id="warning" style="display:none"> Please Complete The Form before submitting</div>
<input type="submit" name="Submit" value="Submit" onclick="checkform(this); return false;" />
</form>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you are welcome
ASKER
Open in new window