I\'d like two submit buttons on a form i have my team building, one above the fold, and one below. I\'m getting complaints from my tech team about adding it because it requi
<input type="button" id="primaryButton" onclick="ExistingLogic()" />
<input type="button" id="secondaryButton"/>
$('#secondaryButton').click(function(){
$("#primaryButton").click();
})
If you want to use vanillaJS to do this... here is a generic very long way (with functions for both to be clear what is happening).
html
<input type="button" id="primaryButton" />
<input type="button" id="secondaryButton"/>
script
const primary = document.getElementById('primaryButton');
const secondary = document.getElementById('secondaryButton');
function somePrimaryAction(e){
e.preventDefault();
console.log('you clicked the primary button');
}
function clickPrimaryButton(e){
e.preventDefault();
console.log('you clicked the secondary button');
primary.click();
}
primary.addEventListener("click", somePrimaryAction, false);
secondary.addEventListener("click", clickPrimaryButton, false);
I'm only familiar with ASP.net and C# buttons, but using C# you could wire two different buttons to the same click event handler. You could also do it client side by triggering the primary buttons click event with your secondary button. Here's a VERY simple example:
HTML
<input type="button" id="primaryButton" onclick="ExistingLogic()" />
<input type="button"
id="secondaryButton"
onclick="document.getElementById('primaryButton').click()" />