how can we get the value of a checked radio button .?
getting value of a radio button....
Collapse
X
-
Tags: None
-
Code:<html> <head> <script type="text/javascript"> function checkThis(ths) { if(ths.checked == true) { alert("You selected "+ths.value); } } </script> </head> <body> <input type="radio" name="sex" value="male" onclick="checkThis(this)"/> Male<br /> <input type="radio" name="sex" value="female" onclick="checkThis(this)"/> Female<br /> </body> </html>
Regards
Ramanan Kalirajan -
or using "this"
Code:<html> <head> <script type="text/javascript"> function checkThis() { if (this.checked == true) { alert("You selected "+this.value); } } attach() { var inp = document.getElementsByName("sex"); inp[0].addEventListener("click", checkThis, false); inp[1].addEventListener("click", checkThis, false); } window.addEventListener("load", attach, false); /* important note IE doesn't understand these Event handlers, use addEvent() (see google) for cross browser support */ </script> </head> <body> <input type="radio" name="sex" value="male"/> Male<br /> <input type="radio" name="sex" value="female"/> Female<br /> </body> </html>
Comment
-
-
Comment
Comment