Showing posts with label radio. Show all posts
Showing posts with label radio. Show all posts

May 22, 2013

Detecting checked radio button on UI dialog

Here is container for jquery UI dialog filled with radio buttons:


<div id="gfdialog" title="Meldung vom Website">
            <div>xxxxxxxxxxxxxxxxxx?</div>
            <input type="radio" name="radLstCopyType" value="1" checked="checked" /><span>Option 1</span>
            <div style="margin-left: 21px!important; margin-bottom: 15px;">Option 2.</div>
            <input type="radio" name="radLstCopyType" value="3" />
            <span>Szenario-CFG</span>
            <div style="margin-left: 21px!important; margin-bottom: 15px;">Option 3</div>
            <input type="radio" name="radLstCopyType" value="2" />
            <span>Muster-CFG</span>
            <div style="margin-left: 21px!important; margin-bottom: 15px;">xxxxxxxxxxxxxxxxxx.</div>
        </div>

; and here is code that gets checked radio button:


function RegisterGFCopyBGDialog() {          
            $("#gfdialog").dialog({
               
                autoOpen: false,
                width: 400,
                buttons: [
                    {
                        text: "Ok",
                        click: function () {
                            var selectedCFG_artId = $('input[name="radLstCopyType"]:checked').val();                          
                           
                            if (selectedCFG_artId == null) return;
                            __doPostBack('radLstCopyType', selectedCFG_artId);
                            $(this).dialog("close");
                        }
                    },
                    {
                        text: "Abbrechen",
                        click: function () {
                            $(this).dialog("close");
                        }
                    }
                ]
            });
        }


Most important part is  :

$('input[name="radLstCopyType"]:checked').val();                           

and NOT:

$('input[name="radLstCopyType"][checked="checked"']).val();                          

or

$('input[name="radLstCopyType"][checked="true"']).val();                          

or

$('input[name="radLstCopyType"][checked]).val();