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!
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>
Hi! thanks for the reply. Problem is I need to use that value later in a variable. Any ideas? thanks!
Sure, save as a global variable instead of alerting the condition.
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!
Try this untested modification...
Originally Posted by
JMRKER
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
Forum Rules
Bookmarks