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;
});
}
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;
});
}
Share
Improve this question
edited Apr 2, 2011 at 4:04
Hussein
42.8k25 gold badges115 silver badges143 bronze badges
asked Apr 2, 2011 at 3:31
pertrai1pertrai1
4,32813 gold badges49 silver badges74 bronze badges
3 Answers
Reset to default 2You 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/xM5E7/
You should check the length property of the jQuery object in your condition.
That...should work. Only think I can suggest is to do this instead:
if($('#addressOverrideLink').length > 0){
/* other stuff here */
}