开发者

How to de-select radio and dropdown

I have group of radiogroup with name managerelradio. I am showing these on change event of dropdown event but issue is when I hide these values remain in radiogroup. Means when I show radiogroup next time selected radio remains selected. How can I deselct it. and same action I wish to perform for dropdown also.

  <label><input type="radio" name="managerelradio" value="Yes" id="Add">Add</label>
  <label><input type="radio" name="managerelradio" value="No" id="Remove">Remove</label> 

 <select name="childsgrel" id="childsgrel" class="select">
 <option value="">--Relationship--</option>
 <option value="Father" <?php if ($relation=="Father") echo "selected";?>>Father</option>
 </select>

Means I want to again disselect both radio group as well as dropdown.

$('#childsgrel').change(function() {
        var relationship = $('#childsgrel').val();
        if(relationship == '' | relationship == null){
      开发者_运维知识库          $('.managechilddiv_2').hide('fast');
                $('input[name="managerelradio"]').attr('selected', false);

            }
        else if(relationship != '' ){
                $('.managechilddiv_2').show('fast');
        }
 });

// I want to disselect radio group on $('#childsgrel').change(function() {...


Without seeing your current jQuery it's hard to say exactly where to put this, but to deselect a selected radio element:

$('input:radio[name="managerelradio"]:checked').prop('checked',false);

JS Fiddle demo.

References:

  • :radio selector.
  • attribute-equals selector.
  • :checked selector.
  • prop().


// Uncheck radios
$(":radio").prop("checked", false);

// Unselect drop-downs
$("select").prop("selectedIndex", -1);

Live Demo on jsFiddle

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜