2

I need to set the hidden input value when a button is clicked and it does not seem to be working.

<input type="hidden" name="addressOverride" id="addressOverride" value="">

Then the button

<button id="addressOverrideLink" class="global-button">Yes this is my correct delivery address</button>

And the code that is trying to set it

if ($('#addressOverrideLink'))
    {
        $('#addressOverrideLink').click(function(e){
            $('#addressOverride').val('YES');
            $('#mainForm').submit();
            return false;
        });
    }

3 Answers 3

2

You can use plain JavaScript to do it

document.getElementById('addressOverride').value = "YES";

Or if you want to use jQuery, do it like this

$('input[name=addressOverride]').val('YES');

Check working example at http://jsfiddle.net/xM5E7/

Sign up to request clarification or add additional context in comments.

Comments

0

You should check the length property of the jQuery object in your condition.

Comments

0

That...should work. Only think I can suggest is to do this instead:

if($('#addressOverrideLink').length > 0){
/* other stuff here */
}

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.