Jenny
Jenny

Reputation: 919

Hide button if radio button is checked on load

"No" is set as the default, I want to hide the submit button if No is selected. On the next page, the submit button uses the same class, i do not want it hidden.

<label>yes, I do agree</label><input type="radio" value="yes, I do agree">
<label>no, I do not agree</label><input type="radio" value="no, I do not agree">

<div class="submit">submit</div>

The problem I am having is if No is set to the default then the submit button is not hidden on load only if I choose Yes then choose No again. If I tell it to hide the submit button on load then on the next step the submit button will be hidden.

Any help would be greatly appreciated.

Upvotes: 1

Views: 615

Answers (3)

KingCodeFish
KingCodeFish

Reputation: 342

You can do something like this to achieve what you desire:

$(".submit").hide();
$("input").click(function() {
    $(".submit").hide();
    if($("input[value=yes]:checked").length) {
        $(".submit").show();
    }
});

jsFiddle: http://jsfiddle.net/kingcodefish/sza8Lb92/

Upvotes: 1

Derek Foulk
Derek Foulk

Reputation: 1902

$(document).ready(function(){
  if ( $('[value^=no]').is(':checked') ) {
    $('.submit').hide();
  }
});

jsFiddle

Upvotes: 0

SunKnight0
SunKnight0

Reputation: 3351

Add an id to the no button (and also recommend id to the submit button). Then:

$(document).ready(function(){       
    if ($('[id of no button]').is(':checked')) $('.submit').hide();
}

Upvotes: 0

Related Questions