SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot McStompin's Avatar
    Join Date
    Oct 2007
    Location
    Wisconsin, U.S.
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using a radio button to generate text

    This might be an easy one. I'm looking to generate text in a simple HTML text box by using a radio button. The concept goes as this:

    User input
    Choose a color:
    (*) Blue () Red () Yella' <---simulated radio buttons w/ blue selected

    Output
    My favorite color is Blue
    ^--- simulated text box with resulting output


    In other words, the radio button selected would generate the underlined word within the sentence in 'real-time' in a text box below the radio buttons. Is this do-able? Thanks!
    A community environment where web designers can share their work:
    RateMyWebPage.net
    Check out and review some new and unique websites or submit your own

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    This should be what your looking for

    HTML Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <script type="text/javascript">
    function setColor(color) {
        var msg  = 'My favorite color is ';
        var form = document.forms['myform'];
        
        form.myColor.value = msg + color;
    }
    </script>
    </head>
    <body>
    
    <form action="" method="post" id="myform">
        <label for="blue">Blue:<label>
        <input type="radio" name="color" value="Blue" id="blue" onclick="setColor(this.value)" />
        <label for="red">Red:<label>
        <input type="radio" name="color" value="Red" id="red" onclick="setColor(this.value)" /><br /><br />
        Color: <input type="text" name="myColor" value="" size="35" />
    </form>
    
    </body>
    </html>

  3. #3
    SitePoint Zealot McStompin's Avatar
    Join Date
    Oct 2007
    Location
    Wisconsin, U.S.
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome, SgtLegend! Thanks a million! That's just what I'm looking for. I will be able to use this. Thanks for the help!
    A community environment where web designers can share their work:
    RateMyWebPage.net
    Check out and review some new and unique websites or submit your own

  4. #4
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Your very welcome


Bookmarks

Posting Permissions

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