I have a web page like this:
<form id="some-form">
<input type='text'>
<button type="submit">
</form>
. . . later in the page . . .
<div id="more-inputs">
<input type="checkbox">
<input type="text">
</div>
For various reasons, the later inputs and check boxes can't go in the original form, but when the form is submitted, I want to use jQuery to gather the values from the checkboxes and the other forms, and submit them as a GET request.
You can tie a submit button to a form that the button doesn't live inside of. The trick is to give the form an id and then reference that id with the button's form property. With this setup, clicking the Submit button will cause the form to be submitted.
1.1 To disable a submit button, you just need to add a disabled attribute to the submit button. $("#btnSubmit"). attr("disabled", true); 1.2 To enable a disabled button, set the disabled attribute to false, or remove the disabled attribute.
That is, the submit() function doesn't actually return anything, it just sends the form data to the server. If you really wanted to get the response in Javascript (without the page refreshing), then you'll need to use AJAX, and when you start talking about using AJAX, you'll need to use a library.
Just trap the submit
event
for your form
?
$('#some-form').submit(function(){
// do work
// do a jquery get or whatever you need to do...
$.get('myurl.html', function(data) {
});
return false; // return false to prevent typical submit behavior
});
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