jQuery selector passes undefined for populated input field
This js script select the value of inputfield with name: id_add_to_cart and pass to ParseProductId that 开发者_JS百科parse the value:
$("input[id='add-extra']").live("click",function () {
var product_id = $("input[name='id_add_to_cart']").value;
parseProductId(product_id);
return false;
});
The parsed value is undefined for this HTML:
<form action="" method="POST">';
<input type="hidden" name="id_add_to_cart" value="100" />
<input type="submit" id="add-extra" value="Add" />';
</form>
What am I missing?
$("input[id='add-extra']").live("click",function() {
var product_id = $("input[name='id_add_to_cart']").val();
alert(product_id);
});
change .value
to .val()
.
Demo: http://jsbin.com/egiwor/2
var product_id = $("input[name='id_add_to_cart']").val();
Does this change anything?
精彩评论