开发者

jQuery selector passes undefined for populated input field

开发者 https://www.devze.com 2023-03-20 04:41 出处:网络
This js script select the value of inputfield with name: id_add_to_cart and pass to ParseProductId that 开发者_JS百科parse the value:

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消