troyvw
asked on
j script radio button
How do i determine if a radio button is selected??
I am trying this :
var ConTVal = $get("rbDevice").checked;
but it returns false every time
I am trying this :
var ConTVal = $get("rbDevice").checked;
but it returns false every time
ASKER
There isn't a way to do it with one line?
You would have to use Jquery ....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So what would the one line be?
if( $("#rbDevice").is(":checke d") = true?
I don't program in java script so I don't know much about the syntax
if( $("#rbDevice").is(":checke
I don't program in java script so I don't know much about the syntax
You said :
>I am trying this :
>var ConTVal = $get("rbDevice").checked;
I propose you a working line doing the same thing with one line :
var ConTVal = $("#rbDevice").is(":checke d");
>I am trying this :
>var ConTVal = $get("rbDevice").checked;
I propose you a working line doing the same thing with one line :
var ConTVal = $("#rbDevice").is(":checke
ASKER
OK, i will check it out in the morning.... if you don't mind my asking what was wrong with me code?
To use it :
if( $("#rbDevice").is(":checked") )
{
// do something if true
}
else
{
// do something if false
}
ASKER
var ConTVall = $("#rbDevice").is(":checke d")
is giving me false every time...
is giving me false every time...
rbDevice is the id of the button radio
ASKER
<input id="rbDevice" type="radio" name="rbgType" value="0" />Device
ASKER
I don't know if this makes a diffrence but there are two rb next to each other: this is the html'
<td style="text-align:left" class="summaryBlackLabel">
Type:<br />
<input id="rbDevice" type="radio" name="rbgType" value="0" />Device
<br />
<input id="rbControl" type="radio" name="rbgType" value="1" />Controller
</td>
<td style="text-align:left" class="summaryBlackLabel">
Type:<br />
<input id="rbDevice" type="radio" name="rbgType" value="0" />Device
<br />
<input id="rbControl" type="radio" name="rbgType" value="1" />Controller
</td>
No problem. Check my test page
$("radio:checked").val()
will return the checked value..
if ( $("radio:checked").val() == "the1iWant" ){
// its checked
}
will return the checked value..
if ( $("radio:checked").val() == "the1iWant" ){
// its checked
}
WilliamStam is absolutely right, :checked selectod should be used that way
http://api.jquery.com/checked-selector/
http://api.jquery.com/checked-selector/
function SelectAll(id) {
var frm = document.forms[0];
for (i=0;i<frm.elements.length
if (frm.elements[i].type == "checkbox") {
frm.elements[i].checked = document.getElementById(id
}
}
}
</script>
Hope this help u..