ivytony Posted February 28, 2008 Share Posted February 28, 2008 I found the source code for javascript to return a radio button value at here http://www.somacon.com/p143.php // return the value of the radio button that is checked // return an empty string if none are checked, or // there are no radio buttons function getCheckedValue(radioObj) { if(!radioObj) return ""; var radioLength = radioObj.length; if(radioLength == undefined) if(radioObj.checked) return radioObj.value; else return ""; for(var i = 0; i < radioLength; i++) { if(radioObj[i].checked) { return radioObj[i].value; } } return ""; } But I want to have the returned value in an input text field named field1. How to do this? thanks! Quote Link to comment Share on other sites More sharing options...
haku Posted February 28, 2008 Share Posted February 28, 2008 // return the value of the radio button that is checked // return an empty string if none are checked, or // there are no radio buttons function getCheckedValue(radioObj) { if(!radioObj) return false; var radioLength = radioObj.length; if(radioLength == undefined) if(radioObj.checked) return radioObj.value; else return false; for(var i = 0; i < radioLength; i++) { if(radioObj[i].checked) { var target = document.getElementById("field1") if(target.setAttribute) { target.setAttribute("value", radioObj[i].value) } else { target.value = radioObj[i].value } } } return false; } <input type="text" name="field1" id="field1" /> I think this should work in firefox, and probably in IE, although I may be wrong. Let me know if it doesn't work. Also, the code wasn't that great (lots of return "" which isn't great code), so I would suggest maybe avoiding that site in the future. 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.