I have the following text box input code. I do not have access to it to add the default value to it so i used this Jquery code to add the value and then disable the input but it doesn’t send the added value. How would I add the value but not allow them to change it. I was going to use “hidden” but I want them to see it just not able to change it.
$("input[type='text'][name='ShipCity']").val('Madison').attr('disabled', 'disabled');
<input type="text" style="background-color: rgb(255, 255, 0);" value="" name="ShipCity" maxlength="45" size="25">
EDIT: Another option would be to disable the fields, and enable them when you submit the form:
I think this should work anyway.
Original answer:
This will
return false;onkeypressevents.Also, it stores the default value using jQuery’s
.data(), and checks that value in ablurevent handler.The reason for this is that it is possible to enter a new value without a keypress event (via the GUI menus).
EDIT:
Here’s a version that will let you do it so that you only need to type the default value once. (It is otherwise identical.)
Example: http://jsfiddle.net/cdzuR/