I have a simple input field inside a form tag:
I'd need to see the whole file but my guess is either you aren't including the jQuery.js source file or you have multiple elements with an ID of foo
I have also been struggling with this. If you set an initial value say '0', and then watch the DOM using something like Firebug you will notice that the DOM then updates. For some reason if the initial value is set to null or an empty string, the DOM does not update, but the value is actually still stored.
You can test this by alerting the val after you have set it (as suggested in earlier posts)
The best answer I found was in the form http://forum.jquery.com/topic/passing-value-to-hidden-form-field.
Instead of $('#Data').val(data);
Where the hidden field ID is 'Data'
Use $('input[name=Data]').val(data);
Works perfectly for me
I figured it out. The value was set by jQuery but when I viewed the source the new value wasn't shown. I tried this (thanks to Fermin):
$('#foo').val('poo')
alert($('#foo').val())
and it displayed the modified value.
I know that it's to late but still this might help someone.... If none of the above solutions work, just do this...
$(document).ready(function() {
$('#foo').attr("value","foo") });
None of the above solutions worked for me.
I had to do the following to make it work:
$('#foo').val(data).blur();