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! Link to comment https://forums.phpfreaks.com/topic/93451-how-to-put-returned-radio-value-to-an-input-text-field/ 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. Link to comment https://forums.phpfreaks.com/topic/93451-how-to-put-returned-radio-value-to-an-input-text-field/#findComment-478833 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.