Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto Selecting field value with event.KeyCode

Status
Not open for further replies.

rmagan

Programmer
Jun 3, 2003
35
US
I have a table of items in a form. I have code to use the up and down arrow to scroll thru the items. I would like the items to be auto-selected when they enter the field. I tried using this.select() in the OnFocus trigger, but that does not work if I use the up/down arrow to get into the field. any ideas?


<html>
<form name=&quot;post_grdbk&quot; action=&quot;stars3.star_portal.process_teacher_gradebook&quot; method=&quot;post&quot;>
<table>
<tr>
<td align=&quot;center&quot; nowrap><strong><input type=&quot;text&quot; name=&quot;p_grd_score&quot; size=&quot;5&quot; maxlength=&quot;5&quot; onFocus=&quot;this.select() ;&quot; value=&quot;10&quot; id=&quot;Cell821732&quot; onKeyDown=&quot;switch(event.keyCode) {case 40: document.post_grdbk.Cell821733.focus();return false; break; case 13: document.post_grdbk.Cell821733.focus();return false; break; case 38: document.post_grdbk.Cell821731.focus();return false; break;}&quot;></strong></td>
</td>
</tr>
<tr>
<td align=&quot;center&quot; nowrap><strong><input type=&quot;text&quot; name=&quot;p_grd_score&quot; size=&quot;5&quot; maxlength=&quot;5&quot; onFocus=&quot;this.select() ;&quot; value=&quot;&quot; id=&quot;Cell831162&quot; onKeyDown=&quot;switch(event.keyCode) {case 40: document.post_grdbk.Cell831163.focus();return false; break; case 13: document.post_grdbk.Cell831163.focus();return false; break; case 38: document.post_grdbk.Cell831161.focus();return false; break;}&quot;></strong></td>
</td>
</tr>
</table>
</form>
</html>
 

Try this:

Code:
<html>
<form name=&quot;post_grdbk&quot; action=&quot;stars3.star_portal.process_teacher_gradebook&quot; method=&quot;post&quot;>
<table>
<tr>
	<td align=&quot;center&quot; nowrap><strong>
		<input type=&quot;text&quot; name=&quot;cell1&quot; size=&quot;5&quot; maxlength=&quot;5&quot; onFocus=&quot;this.select() ;&quot; value=&quot;10&quot; onKeyDown=&quot;switch(event.keyCode) {case 40: document.post_grdbk.cell2.focus();return false; break; case 13: document.post_grdbk.cell2.focus();return false; break; case 38: document.post_grdbk.cell3.focus();return false; break;}&quot;>
	</strong></td>
</tr>
<tr>
	<td align=&quot;center&quot; nowrap><strong>
		<input type=&quot;text&quot; name=&quot;cell2&quot; size=&quot;5&quot; maxlength=&quot;5&quot; onFocus=&quot;this.select() ;&quot; value=&quot;&quot; onKeyDown=&quot;switch(event.keyCode) {case 40: document.post_grdbk.cell3.focus();return false; break; case 13: document.post_grdbk.cell3.focus();return false; break; case 38: document.post_grdbk.cell1.focus();return false; break;}&quot;>
	</strong></td>
</tr>
<tr>
	<td align=&quot;center&quot; nowrap><strong>
		<input type=&quot;text&quot; name=&quot;cell3&quot; size=&quot;5&quot; maxlength=&quot;5&quot; onFocus=&quot;this.select() ;&quot; value=&quot;&quot; onKeyDown=&quot;switch(event.keyCode) {case 40: document.post_grdbk.cell1.focus();return false; break; case 13: document.post_grdbk.cell1.focus();return false; break; case 38: document.post_grdbk.cell2.focus();return false; break;}&quot;>
	</strong></td>
</tr>
</table>
</form>
</html>

Hope this helps!

Dan
 

Incidentally, I didn't change too much - you were trying to reference input fields using their ID instead of their name. Once that was fixed, the rest pretty much worked, as you can see.

Hope this helps,

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top