0

I'm working with Google Checkout and am creating a simple Buy Now button. The button will be on many pages and have many values for the form.

What I'm looking to do is to use Javascript, to get a value on a text_field, and replace a hidden field value.

To get the value, I have this code:

$('#payment_quantity input').keyup(function() {
    var quantity = $('#payment_quantity input').val();
    return false;
});

Then, in the form from google, I have this:

<input type="hidden" name="item_quantity_1" value="1"/>

What I need to be able to do, is replace the value on this hidden input, with my quantity variable. I know this is probably really easy, but I'm amazingly confused at how to do this. I should have to select the hidden field, but I don't know how to update the value?

2 Answers 2

3

Here ya go:

$('input[name="item_quantity_1"]').val(quantity);
Sign up to request clarification or add additional context in comments.

Comments

2

You just have to construct a jQuery selector to get that field and then use the .val(xxx) method to set its value.

jQuery loves to overload the same method for different behaviors based on what you pass as arguments. In the case of .val(), if you pass no arguments, it retrieves the field value. If you pass an argument like .val(quantity), it sets that value into the field like this:

$('#payment_quantity input').keyup(function() {
    var quantity = $('#payment_quantity input').val();
    $("input[name='item_quantity_1']").val(quantity);
    return false;
});

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.