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 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Radio Button OnClick

    I am trying to make it to where when people select a certain radio option, they get a message below the form.

    I am terrible at explaining things. So here is a picture.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Try this:-

    Code:
    <span id = "message">Initial message if any</span><br><br><br>
    
    <form name = "myform">
    <input type = "radio" name = "rad1" id = "rad1" value = "Opt1" onclick = "showMessage()"> Option 1
    <input type = "radio" name = "rad1" id = "rad1" value = "Opt2" onclick = "showMessage()"> Option 2
    </form>
    
    <script type = "text/javascript">
    
    function showMessage() {
    
    var mess1 = "Message appropriate to Option 1"
    var mess2 = "Message appropriate to Option 2"
    
    if (document.myform.rad1[0].checked) {
    document.getElementById("message").innerHTML = mess1;
    }
    else if (document.myform.rad1[1].checked) {
    document.getElementById("message").innerHTML = mess2;
    }
    
    }
    </script>

    It is not as cold as it was yesterday, but that's probably because it's a bit warmer. - Sports commentator


  •  

    Posting Permissions

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