Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-13-2013, 11:17 PM   PM User | #1
JonesJ
New Coder

 
Join Date: Jul 2011
Posts: 36
Thanks: 15
Thanked 0 Times in 0 Posts
JonesJ is an unknown quantity at this point
radio button and javascript to make action

The purpose is to figure out which one of the radio buttons is checked. What is below in the IF statement works if there is no <label> used in the html part. In this case <label> is used so how should the IF statement be modified?

Code:
function set12h24() {
    if (document.switch12h24_form.radio12h24.value == "24h")
    {
        do something here.
    }
}

<div id="radio_side">
    <form name="switch12h24_form">
        <label class="h2412off">&nbsp;<input type="radio" name="radio12h24" value="12h" class="h2412_button" ><a onclick="set12h24()">12h</a></label>
        <label class="h2412off">&nbsp;<input type="radio" name="radio12h24" value="24h" class="h2412_button" ><a onclick="set12h24()">24h</a></label>
    </form>
</div>
Thanks!
JonesJ is offline   Reply With Quote
Old 01-14-2013, 07:41 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
You are trying to make your radio buttons into links. There seems to be no purpose in that.


Code:
<script type = "text/javascript">
function set12h24() {
var r = document.switch12h24_form.rad12h24;
for (var i=0; i<r.length; i++) {
if (r[i].checked) {
var val = r[i].value;
}
}
if (val == "24h") {
alert (val);
// do something here
}
 
}
</script>

<div id="radio_side">
    <form name="switch12h24_form">
        <label class="h2412off">&nbsp;<input type="radio" name="rad12h24" value="12h" class="h2412_button" onclick="set12h24()">12h</label>
        <label class="h2412off">&nbsp;<input type="radio" name="rad12h24" value="24h" class="h2412_button" onclick="set12h24()">24h</label>
    </form>
</div>
Quizmaster: Castel Gandolfo is the summer residence of which religious leader?
Contestant: Jesus
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is online now   Reply With Quote
Users who have thanked Philip M for this post:
JonesJ (01-20-2013)
Reply

Bookmarks

Tags
html, javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:09 PM.


Advertisement
Log in to turn off these ads.