1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Change text based on onclick radio button?

Discussion in 'JavaScript' started by malice95, May 28, 2010.

  1. #1
    I am really new to javascript...

    I can figure out how to get a radio button to call an onclick
    event but how would I use javascript to change some text as a result?

    Example:

    <INPUT TYPE="radio" NAME="price" VALUE="A" CHECKED onClick="setprice("1,900")">A
    <INPUT TYPE="radio" NAME="price" VALUE="B" onClick="setprice("2,010")">B
    <INPUT TYPE="radio" NAME="price" VALUE="C" onClick="setprice("2,100")">C
    <INPUT TYPE="radio" NAME="price" VALUE="D" onClick="setprice("2,500")">D

    function setprice(setting) {
    myOption = setting
    }

    How can I get myOption to dynamically display on the page as each radio button is
    clicked?
    SEMrush
    Thanks,
    Mike
     
    malice95, May 28, 2010 IP
    SEMrush
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    If I have understood you correctly, this is an example how to do that:

    
    <INPUT TYPE="radio" NAME="price" VALUE="A" CHECKED onClick="setprice('1,900')">A
    <INPUT TYPE="radio" NAME="price" VALUE="B" onClick="setprice('2,010')">B
    <INPUT TYPE="radio" NAME="price" VALUE="C" onClick="setprice('2,100')">C
    <INPUT TYPE="radio" NAME="price" VALUE="D" onClick="setprice('2,500')">D
    
    <div id="text"></div>
    
    <script type="text/javascript">
    function setprice(setting) {
        myOption = setting;
        document.getElementById("text").innerHTML = myOption;
    }
    </script>
    
    Code (markup):
     
    s_ruben, May 28, 2010 IP