www.webdeveloper.com
Results 1 to 6 of 6

Thread: Check Which radiobutton is checked

  1. #1
    Join Date
    Mar 2012
    Location
    Ghent
    Posts
    22

    Check Which radiobutton is checked

    (i'm beginner) i'm making an application in which the user selects 1 out of 5 radio boxes and when i click a button i get alerted which one he selects.

    Anyone that can help me? Thanks!
    interactive and development tutorials | http://blog.notflip.be

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,330

    Lightbulb

    There are many ways to solve this, but it is difficult without additional information.

    For example, here is a solution that satisfies your request.
    BUT, it does not use any JS code beyond the 'alert' message.

    Code:
    <!DOC HTML>
    <html>
    <head>
    <title> Untitled </title>
    
    </head>
    <body>
    <input type="radio" name="RBtn" value="A" onclick="alert('You selected: '+this.value)"> A
    <input type="radio" name="RBtn" value="B" onclick="alert('You selected: '+this.value)"> B
    <input type="radio" name="RBtn" value="C" onclick="alert('You selected: '+this.value)"> C
    <input type="radio" name="RBtn" value="D" onclick="alert('You selected: '+this.value)"> D
    <input type="radio" name="RBtn" value="E" onclick="alert('You selected: '+this.value)"> E
    </body>
    </html>

  3. #3
    Join Date
    Mar 2012
    Location
    Ghent
    Posts
    22
    Hi! thanks for the reply. Problem is I need to use that value later in a variable. Any ideas? thanks!
    interactive and development tutorials | http://blog.notflip.be

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,330
    Sure, save as a global variable instead of alerting the condition.

  5. #5
    Join Date
    Mar 2012
    Location
    Ghent
    Posts
    22
    Hi! Thanks for the reply! since i'm new i find it hard to understand what u mean can you please explain litle bit more? thanks!
    interactive and development tutorials | http://blog.notflip.be

  6. #6
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,330

    Lightbulb

    Try this untested modification...
    Quote Originally Posted by JMRKER View Post
    There are many ways to solve this, but it is difficult without additional information.

    For example, here is a solution that satisfies your request.
    BUT, it does not use any JS code beyond the 'alert' message.

    Code:
    <!DOC HTML>
    <html>
    <head>
    <title> Untitled </title>
    <script type="text/javascript">
    var RBtn = false;
    function showRBtnPicked() {
      if (RBtn) { alert('Radio button picked: '+RBtn); }
      else { alert('No radio button chosen') }
    }
    </script>
    </head>
    <body>
    <input type="radio" name="RBtn" value="A" onclick="RBtn=this.value"> A
    <input type="radio" name="RBtn" value="B" onclick="RBtn=this.value"> B
    <input type="radio" name="RBtn" value="C" onclick="RBtn=this.value"> C
    <input type="radio" name="RBtn" value="D" onclick="RBtn=this.value"> D
    <input type="radio" name="RBtn" value="E" onclick="RBtn=this.value"> E
    <p>
    <input type="button" value="Show picked" onclick="showRBtnPicked()">
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles