Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    3 Radio Buttons to Auto Populate a Text Box

    Can you please help me?

    I have a simple form in html with 3 radio Buttons and a text box.

    I simply want to get the text box to display the value of the radio button clicked

    This must be a stroll in the park for you guys out there but for a novice like me it seems impossible.

    Many thanks for your help

    kind regards

    Neil

  • #2
    Regular Coder BonRouge's Avatar
    Join Date
    Mar 2006
    Location
    Sendai, Japan
    Posts
    328
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can do it like this:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Value of radio buttons appearing in text box</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <style type="text/css">
    * {
    margin:0;
    padding:0;
    }
    body {
    background-color:white;
    }
    label {
    display:block;
    margin:10px;
    }
    </style>
    <script type="text/javascript">
    function fillBox() {
    var tradio=document.theform.hobby;
    for (j=0; j<tradio.length; j++) {
    	tradio[j].onclick=function() {
    		for (i=0; i<tradio.length; i++) {
    			if (tradio[i].checked==true) {
    				document.theform.hobbyinput.value=tradio[i].value;
    				}
    			}
    		}
    	}
    }
    window.onload=fillBox;
    </script>
    </head>
    <body>
    <form name="theform" id="theform">
    <fieldset>
    <legend>Legend</legend>
    <label>Which of these do you most enjoy? <input type="text" name="hobbyinput" /></label>
    <label>Crocodile hunting <input type="radio" name="hobby" value="Crocodile hunting" /></label>
    <label>Playing with wild dogs <input type="radio" name="hobby" value="Playing with wild dogs" /></label>
    <label>Reading Schopenhauer <input type="radio" name="hobby" value="Reading Schopenhauer" /></label>
    </fieldset>
    </form>
    </body>
    </html>
    Last edited by BonRouge; 09-22-2006 at 06:50 PM. Reason: to change something...

  • #3
    New to the CF scene
    Join Date
    Sep 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Dear bonrouge

    Thank you so much for your help

    You are a star, it works beautifully


    Kind regards

    Neil


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •