I have a form which I cannot change and I have to handle its submit function from jquery only.
The form have radio buttons only. I want to submit the form without the page refereshed when a radio button is checked.
Here is the code which i tried.
$('input[type="radio"]').click(function(){
if ($(this).is(':checked'))
{
$('form#my-form').submit(function(){
alert('form submitted');
});
}
});
It should alert the "form submitted" but it does not.
Any thing which I am doing wrong?
If you want to submit the form without pageload, then you need to go for ajax.
If you want the alert while submitting, you need to modify ur code a bit..
$('input[type="radio"]').click(function(){
if ($(this).is(':checked'))
{
$('form#my-form').submit();
}
});
$('form#my-form').submit(function(){
alert('form submitted');
});
I tried this example on jsFiddle. My code will submit the form on check of a radioButton.
$('input[type="radio"]').click(function(){
if ($(this).is(":checked"))
$('form#my-form').submit();
});
If you'd like to alert anything on submit of your form you have to add this code
$("#my-form").submit(function() {
alert("submitting form ...");
});
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