I am totally noob for javascript, I just started to learn and I stuck. I am working on ASP.NET app and in my view I create JavaScript function that need to check If checkbox is checked and It need to redirect to next View either if option is Yes or No. For option Yes work perfectlly, but when I select "No" it display required message and in console I get error
Uncaught TypeError: Cannot read property 'checked' of null at YesNoChecked (CreateManually:940) at HTMLButtonElement.onclick (CreateManually:886)
So my code so far
function YesNoChecked() {
var Yes = document.getElementById('Yes');
var No = document.getElementById('No');
if (document.getElementById('Yes').checked ==true) {
console.log('Successfull');
}
if (document.getElementById('No').checked==false) {
console.log('Error');
}
}
HTML
<div class="form-group">
@Html.LabelFor(model => model.Chapel, htmlAttributes: new { @class = "control-label col-md-3" })
<div class="col-md-9">
<label class="radio-inline">
@Html.RadioButtonFor(model => model.Chapel, "Yes", new { @class = "styled", htmlAttributes = new { @checked = "true" } })
Yes
</label>
<label class="radio-inline">
@Html.RadioButtonFor(model => model.Chapel, "No", new { @class = "styled", htmlAttributes = new { @checked = "true" } })
No
</label>
@Html.ValidationMessageFor(model => model.Chapel, "", new { @class = "text-danger" })
</div>
</div>
So basically, either choice is selected "No" or "Yes" it need to redirect to next View, but when choice is selected to "No" it need to hidden element called Chapel. Please help guys :/
If you need some more code let me know, I will publish
UPDATE
Button click
<button type="submit" onclick="YesNoChecked()" class="btn btn-success"><i class="icon icon-check position-left"></i> Proceed to Payment</button>
Radiobutton Yes HTML
<input class="styled" htmlattributes="{ checked = true }" id="Chapel" name="Chapel" type="radio" value="Yes" autocomplete="off">
Radiobutton No HTML
<input checked="checked" class="styled" htmlattributes="{ checked = true }" id="Chapel" name="Chapel" type="radio" value="No" autocomplete="off">