Why My statement is not writing value to hidden field using Jquery
$('#myhidde').attr("value",开发者_开发技巧data[0]['MODE']);
Iam calling ajax page which returns me json data after getting the data from JSON results when i alert also iam able to see the value but iam not able to write to hidden field .What would be the reason .Dying for 2hrs
You need to use val()
for hidden field:
$('#myhidde').val(data[0]['MODE']);
I'm summing up all my comments in an answer here:
Be aware of the following when trying to debug hidden/input field interaction.
- View-Source in browsers shows you the "static" HTML that was part of the original HTTPResponse 1.1 If your browser supports it, try selecting text on the page around the element and choose "view selection source" this typically reveals "up-to-date" source
- If you try to use an onchange event handler on a field to alert the new value after you've set it programatically via JavaScript, it will NOT alert the value because the onchange event only fires when the user interacts with the field to change the value
- Firebug may not appear to update the value of a hidden field under special circumstances (I've witnessed this, but been unable to find a reliable test case to submit a bug) - get a 2nd verification from JavaScript or submitting the page
- Try changing the type attribute temporarily from "hidden" to "text" so that you can see the value when it changes
First check what is inside your data object: console.log( data );
Then, use the correct syntax:
$('#myhidde').val( data[0]['MODE'] );
Use the jQuery val
method:
$('#myhidde').val(data[0]['MODE']);
精彩评论