การเลื่อนเคอร์เซอร์ไปยัง input ตัวถัดไป เมื่อกด Enter

มีคำถามจากบอร์ดถึงการเลื่อนเคอร์เซอร์ไปยัง input ตัวถัดไปเมื่อกด Enter (Cross Browser) ซึ่งโดยปกติแล้ว เรามักใช้การกด TAb เพื่อเลื่อนไปยังตัวถัดไป ผมนำมาลงให้ไว้ที่นี่แล้วครับ
<script type="text/javascript">
function nextbox(e, id) {
   // อ่าน keycode (cross browser)
    var keycode = e.which || e.keyCode;
    // ตรวจสอบ keycode (13 คือ กด enter)
    if (keycode == 13) {
        // ย้ายโฟกัสไปยัง input ที่ id
        document.getElementById(id).focus();
        // return false เพื่อยกเลิกการ submit form
        return false;
    }
}
</script>

<form method="post" action="test.php">
<input type="text" id="no1" onkeydown="return nextbox(event, 'no2');" />
<input type="text" id="no2" onkeydown="return nextbox(event, 'no3');" />
<input type="text" id="no3" />
<input type="submit" />
</form>
ผู้เขียน goragod โพสต์เมื่อ 02 พ.ย. 2553 เปิดดู 15,795 ป้ายกำกับ FormJavascript
^