Reputation: 4318
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;
});
}
Upvotes: 2
Views: 9660
Reputation: 42808
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');
Upvotes: 2
Reputation: 23253
That...should work. Only think I can suggest is to do this instead:
if($('#addressOverrideLink').length > 0){
/* other stuff here */
}
Upvotes: 0
Reputation: 490153
You should check the length property of the jQuery object in your condition.
Upvotes: 0