Reputation: 57
I've got a form with 2 Hidden Fields and i want , when i hit the submit button to fill the fields with my script before sending it . My form looks like this :
<form method = "post" action = "Submit.php">
<input type="text" value="" >
...
<input type"hidden" value="" >
<input type"hidden" value="" >
<input type="submit" value="Sendme">
<script > //do something before send form </script>
The problem is that ive got a field at the end of my form and i need the value of it to fill the hidden fields with some calculation based on his value before the form is submitted.
Upvotes: 4
Views: 7698
Reputation: 6628
As per your question, I assumed that you want to set the values for hidden fields based on the calculation done on the entered value for a first text-box.
You can use the change method of the text-box to set the values of hidden fields, once you submit that will give you values of all the fields.
<input type="text" value="" id="inputBox">
<input type="hidden" value="" id="hidden1">
<input type="hidden" value="" id="hidden2">
$('#inputBox').change(function(){
var value = $(this).val() + 10;
$('#hidden1').val(value);
};
Upvotes: 3