tags:

views:

41

answers:

2

I have the following markup that I need to put the value of the input named "ProductCode" to a variable named lets say product_id using jquery

It's probably easy but for some reason I simply can't figure it out.

<input type="image" src="/v/vspfiles/templates/100/images/buttons/btn_addtocart.gif" id="btnaddtocart" name="btnaddtocart" alt="Add to cart" border="0" onclick="return addToCart2(this.form, this);" />

                          <input type="hidden" name="ReplaceCartID" value="" />
                          <input type="hidden" name="ProductCode" value="M406789" />
                          <input type="hidden" name="e" value="" />

                              <input type="hidden" name="ReturnTo" value="ShoppingCart.asp" />
+2  A: 

You can use jQuery's .val() method.

Try it out: http://jsfiddle.net/uzWJs/

var theValue = $('input[name=ProductCode]').val();

For example:

$('#myForm').submit(function() {
    var theValue = $('input[name=ProductCode]', this).val();
    alert( theValue );
});
patrick dw
LOL, thx this is what I had before var product_id = $("input[name$='ProductCode']");I almost had it just forgot the .val() and remove the quotes
@user - You're welcome. :o)
patrick dw
was going to but it said it had to wait 10 minutes, thx again
+1  A: 

Thats quite simple: Just do this $(document).ready(function() { var product_id = $("input[name='ProductCode']").val(); alert(product_id): //this is the result });

Sudhir
thx and yes that will work but your about 8 hours late, lol