I’m having an issue submitting a form with jQuery’s submit().
I don’t have any elements on my page with a name of name="submit" or name="Submit", same goes for ID’s.
My bit of jQuery code is as follows:
$(document).ready(function () {
$(document).on('click', "#appSubmit",function(e){
e.preventDefault();
var value = $("#time").val();
if(value == "--"){
$( "#err-time" ).dialog( "open" );
}else{
alert("1");
var dummy = $("#appSubmit").val();
alert(dummy);
$("#appSubmit").submit();
alert("2");
}
});
});
All of the alerts work properly, even the alert(dummy); prints out the correct value. The alert("2"); prints out, so it isn’t even breaking on the $("#appSubmit").submit();
My submit button is
<input type="submit" name="appSubmit" id="appSubmit" value="Apply">
Any thoughts would be appreciated, thanks.
EDIT:
I’m sorry, I forgot to post an actual question. The form isn’t submitting when It hits the line $("#appSubmit").submit(); in my code. Nor does it break.
On the jQuery site the examples they give attached the event to the <i+n+p+u+t type="submit">, But I’ve tried it by trying to attach the event to the form’s id and I still got the same behavior. Passes the line with no breaking whatsoever.
The only way I can get it to work is if I use the basic javascript submit call document.applySubmit.submit();
Which is fine, and does the job. But I’d still like to figure this out.
Edit 2:
I will try the .closest approach. I didn’t know what that was until now. Thank you. I will post if it worked.
Edit 3:
Was this question posted 3 times by me? If so, I’m sorry. I must not have been able to find my own question and assumed I never went though the whole question submission process and tried to post it properly a second/third time.
Edit:
Blazemonger suggestion worked.
You don’t
.submit()a button, you.submit()a form. Try:or better yet: