Link to home
Start Free TrialLog in
Avatar of troyvw
troyvwFlag for United States of America

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
Avatar of TonyReba
TonyReba
Flag of United States of America image

<script type="text/javascript">

    function SelectAll(id) {

        var frm = document.forms[0];

        for (i=0;i<frm.elements.length;i++) {

            if (frm.elements[i].type == "checkbox") {

                frm.elements[i].checked = document.getElementById(id).checked;

            }

        }

    }  

</script>

Hope this help u..
Avatar of troyvw

ASKER

There isn't a way to do it with one line?
You would have to use Jquery ....
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of troyvw

ASKER

So what would the one line be?

if( $("#rbDevice").is(":checked") = true?

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(":checked");
Avatar of troyvw

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
}

Open in new window

Avatar of troyvw

ASKER

var ConTVall = $("#rbDevice").is(":checked")

is giving me false every time...
rbDevice is the id of the button radio
Avatar of troyvw

ASKER

<input id="rbDevice" type="radio" name="rbgType" value="0" />Device
Avatar of troyvw

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>
No problem. Check my test page
$("radio:checked").val()
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/