Note that there are some explanatory texts on larger screens.

plurals
  1. POOn tab press call custom function using jquery
    primarykey
    data
    text
    <p>I am trying to create a simple way to insert golf scores into a database. I want to use jquery to make it nice and user friendly. I don't have to worry about anyone not having js enabled as I will be the only using it.</p> <p>I have created a test page you can go to look at what i have so far here,</p> <p>www.barriemenshockey.com/testing/index.php</p> <p><a href="http://www.barriemenshockey.com/testing/index.php" rel="nofollow noreferrer">Score Entry</a></p> <p>Basically I have what I want when the user(me) clicks on a cell, everything works great. But I want to be able to press tab and go to the next hole, type a number hit tab again to go to the next hole and so on. Hopefully this makes sense.</p> <p>Here is the JS I have so far:</p> <pre><code>&lt;script type="text/javascript"&gt; var tabindex = 1; $(document).ready(function() { //on click $("div").click(function() { dowork($(this)); }); $().keypress(function(event) { if (event.keyCode == 9) { var temp = $("#"+tabindex); dowork(temp); $("#10").html(tabindex); } }); }); function dowork(ob) { var number = $(ob).text(); $(ob).empty(); $(ob).append($("&lt;input size=\'2\' style=\'border: none; text-align:center;\'&gt;")); $(ob).find("input").focus(); var input = $(ob).find("input"); input.blur(function(e) { //return it to its last known number if (input.val() == "") input.val(number); else tabindex++; //remove the input html from the div var last = input.val(); $(ob).html(last); }); } &lt;/script&gt; </code></pre> <p>And the structure is like this:</p> <pre><code>&lt;table width="50%" border="1" align="center" cellpadding="0" cellspacing="0"&gt; &lt;tr&gt; &lt;td&gt;1&lt;/td&gt; &lt;td&gt;2&lt;/td&gt; &lt;td&gt;3&lt;/td&gt; &lt;td&gt;4&lt;/td&gt; &lt;td&gt;5&lt;/td&gt; &lt;td&gt;6&lt;/td&gt; &lt;td&gt;7&lt;/td&gt; &lt;td&gt;8&lt;/td&gt; &lt;td&gt;9&lt;/td&gt; &lt;td&gt;Out&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;div id="1"&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="2"&gt;7&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="3"&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="4"&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="5"&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="6"&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="7"&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="8"&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="9"&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="out"&gt;0&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;10&lt;/td&gt; &lt;td&gt;11&lt;/td&gt; &lt;td&gt;12&lt;/td&gt; &lt;td&gt;13&lt;/td&gt; &lt;td&gt;14&lt;/td&gt; &lt;td&gt;15&lt;/td&gt; &lt;td&gt;16&lt;/td&gt; &lt;td&gt;17&lt;/td&gt; &lt;td&gt;18&lt;/td&gt; &lt;td&gt;In&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;div id="10"&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="11"&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="12"&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="13"&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="14"&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="15"&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="16"&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="17"&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="18"&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div id="in"&gt;0&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="9"&gt;&amp;nbsp;&lt;/td&gt; &lt;td&gt;&lt;div id="total"&gt;0&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>Thanks for the help.</p> <p>Nick</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload