Reputation: 12087
I have an input -
<input id="post_name" type="text" value="123" name="post_name">
This input is contained within a <div>
that is hidden when the page loads, and jQuery will not retrieve the value of the input -
var current_name = $('input[name="post_name"]').val();
I can read the rest of the object, and get attirbutes such as name
and id
, but the value is eluding me. Is this a jQuery bug, or am I missing something?
Upvotes: 1
Views: 1701
Reputation: 12087
The answer here is depressingly simple - I accidently duplicated to ID and name that I was using for the input earlier in my code, so it was that which was being picked up by the jQuery.
The lesson I've learned - don't be a donut! And check your code to ensure that selector IDs and input names are not duplicated.
Upvotes: 0
Reputation: 36551
why don't you use 'id' to get the values instead of name... i think that shuold work try this out..
//execute this function whn document is ready
$(document).ready(function() {
//get the val from id
var current_name =$('#post_name').val();
alert(current_name); //alert and see if u getting the value.
});
Upvotes: 2