Posted By

kbrown on 06/09/11


Tagged

form javascript TextField radiobutton


Versions (?)

Populate text field in form with radio button value


 / Published in: JavaScript
 

  1. <html>
  2. <head>
  3. <title>Radio Test</title>
  4. <script type="text/javascript">
  5. function setText(target) {
  6. var txt = document.getElementById(target);
  7. var temp = txt.value;
  8. var tf = document.getElementById("textField");
  9. tf.value = temp;
  10. }
  11. </script>
  12. </head>
  13.  
  14. <body>
  15. <form id="radioform" action="">
  16. <input id="radio1" type="radio" name="r1" value="Okay" onClick="setText('radio1');" />Yes <br/>
  17. <input id="radio2" type="radio" name="r1" value="Nope" onClick="setText('radio2');" />No <br/>
  18. <input type="hidden" id="textField" type="text" name="text" value="Choose One" />
  19. </form>
  20. <body/>
  21. </html>

Report this snippet  

You need to login to post a comment.