How To Include Submit Button Name And Values On Form Serialize() Ajax
I have trouble, my code doesn't work, because my server script side need a name from the submit button. I'm using Ajax method, and I'm using data: serialize, when I have Click on S
Solution 1:
I believe you can't do that but you can use a hidden field
<inputtype="hidden" name="any_name" value="any_value" />
Solution 2:
Try this:
Java Script Code:
<scripttype='text/javascript'>
$(function(){
$('#form').submit(function(e){
e.preventDefault();
var submitData = $('#form').serialize();
var btnName = $('#submit').attr('name');
var btnVal = $('#submit').val();
var btn = '&'+btnName+'='+btnVal;
submitData += btn;
alert(submitData);
});
});
</script>
HTML Code:
<form action=""id="form"type='post'>
<input type="text" name="name"id="name" value='Scott'/>
<input type="submit" name="submit"id="submit" value='POST'/>
</form>
or use:
var submitData = $('#buy_product').serialize();
submitData += '&btnName=' + $('#your_submitbtn_id').attr('name') + '&btnValue='+ $('##your_submitbtn_id').attr('value');
Post a Comment for "How To Include Submit Button Name And Values On Form Serialize() Ajax"