dooballoh Posted April 7, 2007 Share Posted April 7, 2007 How can I put focus on a radio button on "return false" ?Example validation codes; var radioSelected = false; for (var i=0; i<document.formname.gender.length; i++) { if (document.formname.gender[i].checked) radioSelected = true; } if (!radioSelected) { alert('message goes here'); I'd like to put focus here.focus(); return false; } Thank you in advanse. Link to comment Share on other sites More sharing options...
shah_ankitb Posted April 7, 2007 Share Posted April 7, 2007 <form name="formname">Male: <input type="radio" name="gender" value="Male" >Female: <input type="radio" name="gender" value="Female" /><input type="Submit" value="submit" onclick="get_selected();"></form><script type="text/javascript">function get_selected(){ var radioSelected = false; for (var i=0; i<document.formname.gender.length; i++) { if (document.formname.gender.checked) radioSelected = true; } if (!radioSelected) { for (var i=0; i<document.formname.gender.length; i++) { if (!document.formname.gender[0].checked) { document.formname.gender[0].checked = true document.formname.gender[0].focus(); } } }}</script>I am not gettinf the perfect result as u suggest. U can check while u run above code.If u solve that problem then please reply me. Link to comment Share on other sites More sharing options...
dooballoh Posted April 7, 2007 Author Share Posted April 7, 2007 Thank you very much Ankit Shah.Hahaha it's works great. I have an another question.How can I do either highlight, or put border(red) outside of the first radio button(if not possible whole radio group)?So that users can easily see what they are missing.Example HTML;Male: <input type="radio" name="gender" value="Male" />Female: <input type="radio" name="gender" value="Female" />Either 1. highlight, or red border on "Male" radio button2. red border around whole "Male" and "Female" radio group.Thank you very much in advance. Link to comment Share on other sites More sharing options...
Bassam122 Posted April 9, 2007 Share Posted April 9, 2007 Thank you very much Ankit Shah.Hahaha it's works great. I have an another question.How can I do either highlight, or put border(red) outside of the first radio button(if not possible whole radio group)?So that users can easily see what they are missing.Example HTML;Male: <input type="radio" name="gender" value="Male" />Female: <input type="radio" name="gender" value="Female" />Either 1. highlight, or red border on "Male" radio button2. red border around whole "Male" and "Female" radio group.Thank you very much in advance.hi, try:<input type="radio" ....... style= bgcolor:"red">or<input type="radio" ....... style= color:"red">and let me know if it worked plz. Link to comment Share on other sites More sharing options...
dooballoh Posted April 13, 2007 Author Share Posted April 13, 2007 Thank you very much Bassam.But no, it doesn't works.Any other ways?Thank you in advance. Link to comment Share on other sites More sharing options...
aspnetguy Posted April 13, 2007 Share Posted April 13, 2007 style="background: red" or style="border: 1px solid red" Link to comment Share on other sites More sharing options...
dooballoh Posted April 14, 2007 Author Share Posted April 14, 2007 Aaah~~Thank you very much to all of you. 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