Trigger OK button by pressing "Enter" (instead of clicking on it)

Where is my mistake?

I'd like to trigger OK button by pressing "Enter" (instead of clicking on it)

<div class="buttonbar">
				<button name="Cancel" type="button" onclick="window.KeyboardMaestro.Cancel('Cancel')">Cancel</button> 
				<button name="OK" type="submit" id="submit" onclick="window.KeyboardMaestro.Submit('OK')">OK</button>
				
					<script>
						document.getElementById("submit")
    					.addEventListener("keyup", function(event) {
    					event.preventDefault();
    					if (event.keyCode === 13) {
        				document.getElementById("submit").click();
    					}
						});

						function buttonCode()
						{
  						alert("Button code executed.");
						}
					</script>
			</div>

This would probably have more chance of getting a good answer on a DOM scripting forum since it doesn't seem to have anything to do with Keyboard Maestro.

Thanks, I'll look into it.

1 Like

Oh, if you look at one of my macroapps that uses a Custom HTML Prompt (like Mirror Mirror), you'll see the JS I used to trigger various keys, including Enter and Escape.

Thanks, I'll check it out!