|
-
Sep 14th, 2004, 12:58 AM
#1
Thread Starter
Frenzied Member
textbox focus
hi to everyone im very new in this thing.
why this code wont work?
whats wrong w/ it?
what i want to achieve is when i hit the enter key it will get focus to another textbox..
PHP Code:
<form>
<input type="textbox" name="textbox1" onkeypress="keydown(event)" >
<input type="textbox" name="textbox2">
</form>
<script>
function keydown(e){
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
if (code==13){
textbox2.focus();
}
}
</script>
thanks in advance guys..
more power
-
Sep 14th, 2004, 03:16 AM
#2
Frenzied Member
it said textbox2 is undefined. This is because you've addressed the thing wrongly, this will work:
Code:
<form>
<input type="textbox" id="textbox1" onkeypress="keydown(event)" >
<input type="textbox" id="textbox2">
</form>
<script>
function keydown(e){
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
if (code==13){
document.getElementById('textbox2').focus();
}
}
</script>
Have I helped you? Please Rate my posts. 
-
Sep 14th, 2004, 04:10 AM
#3
Thread Starter
Frenzied Member
hi acidic i tried what you have given me but still it wont work..
what's wrong w/ it?
PHP Code:
<form>
<input type="textbox" name="textbox1" onkeypress="keydown(event)">
<input type="textbox" name="textbox2">
</form>
<script language="javascript">
function keydown(e){
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
if (code==13){
document.getElementById("textbox2").focus();
}
}
</script>
sorry for my stupidity im very new in this thingy.
-
Sep 14th, 2004, 04:36 AM
#4
Frenzied Member
what I posted did work. look at the function getElementByID(). You need to specify an id, not a name, for puposes on server-side code maybe you need both id and name attributes.
so change thos names back to ids and you're off.
Have I helped you? Please Rate my posts. 
-
Sep 14th, 2004, 08:21 PM
#5
Thread Starter
Frenzied Member
thanks man...
works perfect
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|