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.
I have created a test page you can go to look at what i have so far here,
www.barriemenshockey.com/testing/index.php
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.
Here is the JS I have so far:
<script type="text/javascript">
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($("<input size=\'2\' style=\'border: none; text-align:center;\'>"));
$(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);
});
}
</script>
And the structure is like this:
<table width="50%" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>Out</td>
</tr>
<tr>
<td><div id="1"> </div></td>
<td><div id="2">7</div></td>
<td><div id="3"> </div></td>
<td><div id="4"> </div></td>
<td><div id="5"> </div></td>
<td><div id="6"> </div></td>
<td><div id="7"> </div></td>
<td><div id="8"> </div></td>
<td><div id="9"> </div></td>
<td><div id="out">0</div></td>
</tr>
<tr>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>In</td>
</tr>
<tr>
<td><div id="10"> </div></td>
<td><div id="11"> </div></td>
<td><div id="12"> </div></td>
<td><div id="13"> </div></td>
<td><div id="14"> </div></td>
<td><div id="15"> </div></td>
<td><div id="16"> </div></td>
<td><div id="17"> </div></td>
<td><div id="18"> </div></td>
<td><div id="in">0</div></td>
</tr>
<tr>
<td colspan="9"> </td>
<td><div id="total">0</div></td>
</tr>
</table>
Thanks for the help.
Nick