Gurnoor Kahlon Gurnoor Kahlon - 1 year ago 81
Javascript Question

I'd like to trigger a function on key and on click

I currently have a function run when the calculate button is clicked.

<button class="hvr-shrink" type="submit" value="submit" id="submit"> Calculate </button>

I want that the function runs when I not only click the submit button but also the ENTER KEY

Function works with perfection just want it to also work when user hits enter

Check the javascript here!

HTML to the function




<link href="../CSS files/style.css" rel="stylesheet" type="text/css">
<link href="../CSS files/hover.css" rel="stylesheet" type="text/css">
<link href=',300,600,700,800' rel='stylesheet' type='text/css'>


<div id="home">
<a href="home.html">
<img class="hvr-shadow" src="../../misc/hoem.png" id="homeicon">
<h1>Geometric Sequence</h1>
<h2>Find any term of a Geometric Sequence</h2>

<input id="firstTerm" placeholder="First Term?">
<input id="nTerm" placeholder="Nth Term?">
<input id="commonR" placeholder="Common Ratio?">

<button class="hvr-shrink" type="submit" value="submit" id="submit"> Calculate </button>

<p id="term"> </p>


<script type="text/javascript" src="../math fxn (js)/geoseq.js"></script>
<script src=""></script>

<script src=""></script>



Answer Source

Check out the fiddle I have worked on mate and let me know if this is what you need and lets update it to what you want. . .

   if ( event.which == 13 ) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download