changing form post
I want to change form post data before send. i use some java script code to get some user inputs and want to 开发者_Go百科attach those to request post data. I wanna a normal post that cause to display result as a an HTML page. its may be useful that i linked JQuery and can use its functions. Thanks very much!
You can use onSubmit
event as shown below -
<form action="test.php" name="testform" onSubmit="return TestDataCheck()" >
<input type="text" value="hello" name="testinput" />
<form>
Define a function as shown below -
<script type="text/javascript">
function TestDataCheck(){
//Here do whatever you want to do with the form or it's values.
//I am changing the value of input field in the form for your reference in same way you
//can change any elements value.
$('input[name="testinput"]').val("bye");
return true.
}
</script>
html
<form action="test.php" name="testform" id="testForm">
<input type="text" value="hello" name="testinput" />
<form>
javascript
//handle form submit
jQuery("#testForm").submit(function(e){
//prevent default action
e.preventDefault;
//get form
var _data=jQuery("#testForm").serialize();
//add custom props
_data['customProp1']='customValue1';
_data['customProp2']='customValue2';
//now just submit form or call ajax
});
精彩评论