Reputation: 919
"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
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
Reputation: 1902
$(document).ready(function(){
if ( $('[value^=no]').is(':checked') ) {
$('.submit').hide();
}
});
Upvotes: 0
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