javascript - Validating input field based on radio input and display error message -


i'm trying display error message using jquery while submitting form, when radio button selected true , input box empty, reason failing. suggestions appreciated!

<div class="row col-lg-offset-2 top-buffer"> <h4>     <strong>         <span>is account deleted?:</span>     </strong> </h4>             @html.radiobuttonfor(model => model.isdeleted, true) @html.label("yes")             @html.radiobuttonfor(model => model.isdeleted, false) @html.label("no")  <br> </div> <div class="row col-lg-offset-2 top-buffer" id="reason">     <div class="col-sm-2">         <b>reason delete:</b>     </div>     <div class="col-sm-10">         @html.textboxfor(model => model.reason, new { @class = "form-control", @id = "reason" })          <br />     </div>     <div class="row col-sm-12">         <label id="lblerrormsg" class="has-error" style="color: #bd362f"></label>     </div>     <div class="col-sm-4">         <button type = "submit" id="next" name="next" class="btn btn-primary">next</button>     </div> </div> 

script:

<script> $("#next").click(function () {     if ($("input[name='isdeleted']" === "true" && $("#reason").val(''))) {         $("#lblerrormsg").text("please enter meter number");     } else {         $("#lblerrormsg").text("");     } }); 

i can't sure since don't see full html code try instead of:

if ($("input[name='isdeleted']" === "true" && $("#reason").val(''))) { 

this:

if ($("input[name='isdeleted']:checked").val() === "true" && $("#reason").val() == '') 

improved answer bit, make sure isdeleted radio button has value "true"


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -