how to validate the form using jquery
Posted
by kumar
on Stack Overflow
See other posts from Stack Overflow
or by kumar
Published on 2010-05-26T16:40:35Z
Indexed on
2010/05/26
16:51 UTC
Read the original article
Hit count: 228
I have this Fieldset values..
<fieldset class="clearfix" id="fieldset-exception">
<legend>Mass Edit Exception Information</legend>
<div id="#error-msg-ID" class="ui-widget hide">
<div class="ui-state-highlight ui-corner-all">
<p><span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-info"></span>
<span></span></p>
</div>
</div>
<div class="fiveper">
<label for="ExceptionStatus">
Status:
<span> </span>
</label>
<label for="ResolutionCode">
Resolution:
<span>
<%=Html.DropDownListFor(model => model.Exception.ResolutionCode, new SelectList(Model.LookupCodes["C_EXCPT_RESL"], "Key", "Value"))%>
</span>
</label>
<label for="ReasonCode">
Reason:
<span><%=Html.DropDownListFor(model => model.Exception.ReasonCode, new SelectList(Model.LookupCodes["C_EXCPT_RSN"], "Key", "Value"))%></span>
</label>
<label for="ExceptionStatus">
Action Taken:
<span><%=Html.DropDownListFor(model => model.Exception.ActionCode, new SelectList(Model.LookupCodes["C_EXCPT_ACT"], "Key", "Value"))%></span>
</label>
</div>
<div class="fiveper">
<label for="FollowupDate">
Follow-up:
<span><input type="text" id="exc-flwup" name="fdate" /></span>
<%--<%=Html.EditorFor(model=>model.Exception.FollowupDate) %>--%>
</label>
<label for="IOL">
Inquiry #:
<%=Html.TextBox("Inquiry", ViewData["inq"] ?? "")%>
</label>
<label>Comment</label>
<span>
<%=Html.TextArea("value", ViewData["Comnt"] ?? "")%>
<%=Html.ValidationMessage("value")%>
</span>
</div>
<br />
<br />
<div>
<input type="submit" class="button" value="Save" />
</div>
</fieldset>
before submiting I need to do some time of validation..below validation not working for me is that right what I am doing here? These all fieds user is entering from UI.. thanks
<script type="text/javascript">
$(document).ready(function() {
$('#btnSelectAll').click(function() {
$('#EditExceptions input[name=chk]').attr('checked', true);
});
$('#btnCancel').click(function() {
$('#EditExceptions input[name=chk]').attr('checked',false);
});
function validate_excpt(formData, jqForm, options) {
var form = jqForm[0];
**if (form.e_Exception_ResolutionCode.value && !form.e_Exception_ReasonCode.value) {
alert('All Resolution Codes need a Reason Code.');
return false;
}**
}
// post-submit callback
function showResponse(responseText, statusText, xhr, $form) {
if (responseText[0].substring(0, 16) != "System.Exception") {
$('#error-msg-ID span:last').html('<strong>Update successful.</strong>');
$().ShowDialog('Success', 'Update successful');
} else {
$('#error-msg-ID span:last').html('<strong>Update failed.</strong> ' + responseText[0].substring(0, 48));
$().ShowDialog('Failed', 'Update failed');
}
$('#error-msg-ID').removeClass('hide');
$('#gui-stat-').html(responseText[1]);
}
$('#exc-').ajaxForm({
beforeSubmit: validate_excpt,
success: showResponse,
dataType: 'json'
});
$('.button').button();
$("input[id^='exc-flwup']").datepicker({
duration: '',
showTime: true,
constrainInput: true,
stepMinutes: 30,
stepHours: 1,
altTimeField: '',
time24h: true,
minDate: 0
});
$('#ui-timepicker-div').bgiframe();
});
</script>
© Stack Overflow or respective owner