We're using some very simple jQuery to change the value of our text field:
<input type="text" name="rabatt" id="sonderrabatt" value="">
var sonderrabatt = 10;
$('#sonderrabatt').val(sonderrabatt);
This changes the value displayed in the browser, does NOT however change the value attribute of our text field in the source code.
Now, consider this:
<input type="hidden" name="rabatt" id="sonderrabatt" value="">
var sonderrabatt = 10;
$('#sonderrabatt').val(sonderrabatt);
Change the input type to hidden and the value attribute DOES change!
1.Does this mean we have to do the following to change our input field's value displayed in the browser AND its value attribute in the source code?:
<input type="text" name="rabatt" id="sonderrabatt" value="">
var sonderrabatt = 10;
$('#sonderrabatt').val(sonderrabatt);
$('#sonderrabatt').attr('value',sonderrabatt);
2.Why does .val() work for type=hidden and NOT for type=text input fields?