jquery - how to submit the form after name check availability? -
my code working fine! jsp page when submit form, based on name availability,it has submit, example if name available storing ,the form has submit otherwise form should not submit. in jsp:
<form action="<%=editcourseurl%>" method="post" id="register-form" > <div class="label1">course name</div> <input type="text" id="cname" name="cname" value=" "/> <input type="submit" id="submit1" value="check availability" /> <div id="message" ></div> <br /> <div class="label2">course description</div> <input type="text" id="cdesc" name="cdesc" value=""/><br/> <div class="label3">start date</div> <input type="date" name="sdate" id="sdate" value=""/><br/> <div class="label4">end date</div> <input type="date" id="edate" name="edate" value="" /><br /> <input type="submit" id="submit" value="submit" /> </form> <liferay-ui:success key="key" message="message" /> <portlet:renderurl var="homeurl"> <portlet:param name="jsppage" value="/html/course/view.jsp"></portlet:param> </portlet:renderurl> <portlet:resourceurl var="resourceurl"></portlet:resourceurl> <script src="//code.jquery.com/jquery-1.9.1.js"></script> <script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script> <script type="text/javascript"> $(document).ready(function() { // setup form validation on #register-form element $("#register-form").validate({ // specify validation rules rules: { cname: "required", cdesc: "required", sdate: "required", edate: "required" }, // specify validation error messages messages: { cname: "<p><font color=red>please enter course name</p></font>", cdesc: "<p><font color=red>please enter course description</p></font>", sdate: "<p><font color=red>please enter start date</p></font>", edate: "<p><font color=red>please enter end date</p></font>" }, submithandler: function(form) { form.submit(); } }); $("#submit1").click(function(){ var nameval = jquery("#cname").val(); jquery.ajax({ url :'<%=resourceurl%>', data:{cname:nameval}, type: "post", datatype: "json", success: function(data){ { if(nameval==data["cname"]) { $("#message").html("<font color=red>course name exist.</font>"); return true; } else $("#message").html("<font color=green>course name available</font>"); return false; } } }); }); }); </script> <liferay-ui:success key="del" message="course-created-sucessfully" /> <% } %>
please can body me? have submit form based on availability of course name
within <form>
, have 2 different buttons both contain type="submit"
attribute. means clicking either button try submit whole form.
<input type="submit" id="submit1" value="check availability" />
since want first button remote check based on .click()
handler, you'll need prevent submitting form. changing type="button"
.
<input type="button" id="submit1" value="check availability" />
Comments
Post a Comment