By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,773 Members | 1,131 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,773 IT Pros & Developers. It's quick & easy.

Focusing the cursor to the first text box of Each row

P: 8
Hi,

I wrote the code to generate a new row each time when i press tab in the
second text box in a row of two text boxes. It's working fine. But my problem is
in the new row that is created when i press tab, the cursor should be in the first
text box. I wrote the code for that. It's line 10 and 11.
It's not working. Please let me know the solution.
More over when i press tab in the 2nd text box of first row the cursor is going to
second text box of second row and when i press tab from the second text box of
second row the cursor is not at all seen.
I spent a lot of time on this.


Thanks in advance.
The html file is below.


<html>
<head>
<script>
var numOfLines = 2;
function generateRow()
{
var d=document.getElementById("div");
d.innerHTML += "<input type='text' name='quantity"+numOfLines+"'>&nbsp&nbsp";
d.innerHTML += "<input type='text' name='itemCode"+numOfLines+"' onkeydown='if(event.keyCode==9){generateRow();}'>< br>" ;
var felement = eval("document.forms[0].quantity"+numOfLines);
felement.focus();
numOfLines += 1;
}

</script>
</head>
<body>
<form>

Quantity &nbsp&nbsp ItemCode<br>
<input type=text name="quantity1" >
<input type="text" name="itemcode1" onkeydown="if(event.keyCode==9) {generateRow();}">

<div id="div"></div>
</form>
<body>
</html>
Feb 24 '07 #1
Share this Question
Share on Google+
10 Replies

dmjpro
100+
P: 2,476
look... try to avoid overriding the default behaviour of browser ...

try to add onle line at the end of the generateRow function ...
then check it out

return false;

actually sometimes i also fail to stop default behaviour of the browser.
return false means stop the default behaviour of the browser


welcome in advance
Feb 24 '07 #2

P: 8
Hi,

I added
return false;
to the above code. It works for the 2nd line, but not for the 3rd line onwards.
Feb 24 '07 #3

iam_clint
Expert 100+
P: 1,208
hi this should need no javascript look for help in html forum for tabindex.
Feb 24 '07 #4

P: 8
Hi,

I wrote the code to generate a new row each time when i press tab in the
second text box in a row of two text boxes. It's working fine. But my problem is
in the new row that is created when i press tab, the cursor should be in the first
text box. I wrote the code for that. It's line 10 and 11.
It's not working. Please let me know the solution.
More over when i press tab in the 2nd text box of first row the cursor is going to
second text box of second row and when i press tab from the second text box of
second row the cursor is not at all seen.
I spent a lot of time on this.


Thanks in advance.
The html file is below.


<html>
<head>
<script>
var numOfLines = 2;
function generateRow()
{
var d=document.getElementById("div");
d.innerHTML += "<input type='text' name='quantity"+numOfLines+"'>&nbsp&nbsp";
d.innerHTML += "<input type='text' name='itemCode"+numOfLines+"' onkeydown='if(event.keyCode==9){generateRow();}'>< br>" ;
var felement = eval("document.forms[0].quantity"+numOfLines);
felement.focus();
numOfLines += 1;
}

</script>
</head>
<body>
<form>

Quantity &nbsp&nbsp ItemCode<br>
<input type=text name="quantity1" >
<input type="text" name="itemcode1" onkeydown="if(event.keyCode==9) {generateRow();}">

<div id="div"></div>
</form>
<body>
</html>
Feb 25 '07 #5

dmjpro
100+
P: 2,476
plz tell me indetails where added return false ... and i don't understand ur answer ...... i think i can figure u out why it happens
Feb 26 '07 #6

dmjpro
100+
P: 2,476
u already posted this code and some responses come ....plz check them out
Feb 26 '07 #7

P: 8
Hi,
At line number 15, i added
return false;
The code is below.


<html>
<head>
<script>
var numOfLines = 2;
function generateRow()
{
var d=document.getElementById("div");
d.innerHTML += "<input type='text' name='quantity"+numOfLines+"'>&nbsp&nbsp";
d.innerHTML += "<input type='text' name='itemCode"+numOfLines+"' onkeydown='if(event.keyCode==9){generateRow();}'>< br>" ;
/*
var felement = eval("document.forms[0].quantity"+numOfLines);
felement.focus();
*/
numOfLines += 1;
return false;
}

</script>
</head>
<body>
<form>

Quantity &nbsp&nbsp ItemCode<br>
<input type=text name="quantity1" >
<input type="text" name="itemcode1" onkeydown="if(event.keyCode==9) {generateRow();}">

<div id="div"></div>
</form>
<body>
</html>
Feb 26 '07 #8

dmjpro
100+
P: 2,476
good to see someone trying ......

Now add return false ... in two places .... instead of at the last of generateRow() function.

1. d.innerHTML += "<input type='text' name='itemCode"+numOfLines+"' onkeydown='if(event.keyCode==9){generateRow();retu rn false;}'><br>" ;

2.<input type="text" name="itemcode1" onkeydown="if(event.keyCode==9) {generateRow();return false;}">

try ittt ...

best of luck .....
Feb 27 '07 #9

P: 8
hi,

Still it's not working. I am using IE7.
Feb 27 '07 #10

acoder
Expert Mod 15k+
P: 16,027
Threads merged. Please do not double post.
Feb 27 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.