Reputation: 803
I have a little bit of a different situation. I have 2 radio buttons, Yes and No. The first validation needs to make sure at least one of them are checked. This part works fine. The second part needs to make sure No was checked since No is the only valid option. If they pick Yes, it should continue to prompt them.
Normally I would use a checkbox for this but the business wants to force a Yes or No. I thought maybe I could have added choices but that doesn't do what I need.
optionPlan: {
validators: {
notEmpty: {
message: 'Please select Yes or No'
},
}
}
Upvotes: 0
Views: 1232
Reputation: 178
or you could use :
<form class="form-signin" action="firstLogin.action" method="post">
<h2 class="form-signin-heading">Please sign in</h2>
<input type="text" class="form-control" name="username" placeholder="User Name">
<br>
<input type="password" class="form-control" name="password"placeholder="Password">
<br>
<div >
<input type="radio" name="yes">Yes</input>
<input type="radio" name="radio-choice" required>No</input>
</div>
<div>
<br>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
<script>
if ($('input[name=yes]:checked').length > 0) {
// do something here
alert("you need to select no !");
}
</script>
Upvotes: 1
Reputation: 178
if ($('input[name=yes]:checked').length > 0) {
// do something here
alert("you need to select no !");
}
Upvotes: 1