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 Answers 2

4

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 );
});
Sign up to request clarification or add additional context in comments.

2 Comments

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
was going to but it said it had to wait 10 minutes, thx again
2

Thats quite simple, just do this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.