I’m trying to get the return key to function as the tab key but it dosent work with tables. Here is the fiddle.
I’m not sure whats causing it not to work when I remove the table and use <br /> it works perfectly. It also works with the jQuery calculator function. thought that was causing the problem but its not. I’m not sure if I’m asking jQuery to do something that a library would be better for.
HTML
<table border="1">
<tr>
<td id="larger">field 1</td>
<td>
<input type="text" id="sum1" name="sum1" class="sum" size="15" border="0"
/>
</td>
<td>
<input type="text" id="sum2" name="sum2" class="ttw" size="15" />
</td>
<td>
<input name="cash" type="text" class="cash" id="cash1" value="" size="15"
/>
</td>
</tr>
</table>
jQuery
$('table:input').keydown(function (event) {
if (event.which == 13) {
if (!$(this).hasClass("last")) {
event.preventDefault();
$(this).nextAll('input:first').focus();
} else {
$("form").submit();
}
}
});
$(function () {
$('input[name^=sum]').keyup(function () {
var sum1 = parseFloat($('input[name=sum1]').val(), 2) || 0; // Or parseInt if integers only
var sum2 = parseFloat($('input[name=sum2]').val(), 2) || 0;
$('#cash1').val(sum1 + sum2);
});
});
$(function () {
$('input#cash1').blur(function () {
var amt = parseFloat(this.value, 2) || 0;
$(this).val('' + amt.toFixed(2));
});
});
You could do something like http://jsfiddle.net/Beyq7/6/
$(this).parent().next().children('input:first').focus();