'I need a ctrl+click feature that performs 2 functions [duplicate]
I am still trying to learn javascript and don't quite have the syntax down yet. My client wants a ctrl+click feature on a button. If the button is just clicked, I want it to execute the existing code to go to Paypal, if the button is clicked with the ctrl key pressed, I want it to go to a different page altogether. I pulled this snippet from w3school and I got it to work for the button, but obviously alerts are not what I need.
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" onmousedown="isKeyPressed(event)">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="L7XXXXXXXXXYU">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
<script>
function isKeyPressed(event) {
if (event.ctrlKey) {
alert("The CTRL key was pressed!"); <- I want to go to different .html page
} else {
alert("The CTRL key was NOT pressed!"); <- I want to execute the Paypal instructions
}
}
</script>
I cannot seem to find the correct syntax to make this happen. I presume I need a === NULL somewhere to trigger Paypal and something else to go to the external HTML page. I'm at a loss.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|