Am trying to submit a form using jQuery. My code below
<form id="sampleForm" action="@Url.Action("submitSearch","Home")">
//Form Fields textbox
<button id="test" type="submit" ></button>
</form>
Inside document.ready
having script
$("#sampleForm").submit(function () {
console.log("Success");
});
But when click sumbit nothing is happening.
I tried the below code to see if I have mapped correctly and that works fine
$(document).on("click", "#search-button", function () {
console.log("Success");
});
What am missing while submitting form ?
$("#sampleForm"). submit(function () { console. log("Success"); });
jQuery submit() MethodThe submit event occurs when a form is submitted. This event can only be used on <form> elements. The submit() method triggers the submit event, or attaches a function to run when a submit event occurs.
$("#test").click(function(){
$("#sampleForm").submit();
});
Is it possible you're submitting but the page is reloading and the console log is cleared?
Also, just to clarify...
$("#sampleForm").submit(function () {
console.log("Success");
});
This wires up an event to do stuff when the sampleForm is submitted...
$('#sampleForm').submit();
actually triggers the submit event
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With