fn. get radio button value


/ Published in: JavaScript
Save to your folder(s)

/* How to use */
var prima = getCheckedValue(document.forms["myForm"].elements['myRadio'])


Copy this code and paste it in your HTML
  1. function getCheckedValue(radioObj) {
  2. if(!radioObj)
  3. return "";
  4. var radioLength = radioObj.length;
  5. if(radioLength == undefined)
  6. if(radioObj.checked)
  7. return radioObj.value;
  8. else
  9. return "";
  10. for(var i = 0; i < radioLength; i++) {
  11. if(radioObj[i].checked) {
  12. return radioObj[i].value;
  13. }
  14. }
  15. return "";
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.