javascript - jQuery validation for textbox and Radio buttons -
javascript - jQuery validation for textbox and Radio buttons -
i have form in "jquery dialog box" , in there <textarea>
, other pair of <input type="radio" />
buttons
both required fields , if user leaves testarea empty or not check of radio , user should message , dialog box should not close.
i have tried doing validation, working textarea not radio buttons.
here fiddle created : http://jsfiddle.net/jldf5/
here code same:
html
<div id="sessionreason" title="end transaction"> <p class="validation-summary-errors marginbottom10">provide next info proceed:</p> <div class="marginbottom" id="sessiondocumentmessage"> <label class="marginbottom5 margintop10">return document?</label> <br> <label> <input type="radio" name="sessiondocuments" />return</label> <br> <label> <input type="radio" name="sessiondocuments" />keep</label> <br> </div> <p class="marginbottom5" id="sessionreasonmessage">reason ending transaction:</p> <textarea id="sessionreasonbox" class="reasonbox"></textarea> </div>
jquery
$('#sessionreason .validation-summary-errors').hide(); $("#sessionreason").dialog({ buttons: { "end transaction": function () { var sessionreasonbox = $("#sessionreasonbox").val(); if ($('[name="sessiondocuments"]').is(':checked')){ $('#sessionreason .validation-summary-errors').show(); $("#sessiondocumentmessage label").addclass("redtext"); } if (sessionreasonbox == "") { $('#sessionreason .validation-summary-errors').show(); $("#sessionreasonmessage").addclass("redtext"); homecoming false; } else { $('#sessionreason .validation-summary-errors').hide(); $("#sessionreasonmessage").removeclass("redtext"); } $(this).dialog("close"); }, "cancel": function () { $(this).dialog("close"); } } });
please suggest!
if blocks needs else if , close should within if block. , check ! (not) radio checked. , no need homecoming false.
if (!$('[name="sessiondocuments"]').is(':checked')){ $('#sessionreason .validation-summary-errors').show(); $("#sessiondocumentmessage label").addclass("redtext"); } else if (sessionreasonbox == "") { $('#sessionreason .validation-summary-errors').show(); $("#sessionreasonmessage").addclass("redtext"); //return false; } else { $('#sessionreason .validation-summary-errors').hide(); $("#sessionreasonmessage").removeclass("redtext"); $(this).dialog("close"); }
here fiddle
javascript jquery html validation jquery-ui-dialog
Comments
Post a Comment