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

can we focus two textfields at a time

P: 12
I have requirement like the first page contains LoginName and CompanyName after typing the value clicking Submit button so i am giving in body onload="document.forgotPassword.loginName.focus(); document.forgotPassword.securityAnswer.focus();"

bcoz after giving correct value by clicking submit button it is going to the same page with some otherfields like
Login Name
Coompany Id
Security Question
Security Answer here i need to focus

my code


[HTML]<body class="FormTableBackground" onload="document.forgotPassword.loginName.focus(); document.forgotPassword.securityAnswer.focus();">
<form name="forgotPassword" method="post" action="eventhandler">
<center>
<div class="topLocation"><%@include file="login_top_bar.jsp"%>
<div class="FormTableBackground">
<table width="100%" border="0" height="100%">
<tr>
<td colspan="3">
<table width="53%" height="100%" align="center" cellspacing="0">
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3">
<table width="53%" height="100%" align="center" cellspacing="0">
<tr class="copyRight">
<td height="7%" width="100%" align="left"><font size="+1">Forgot Password</font> </td>
</tr>
<%if((loginInfo=="invalidLoginInfo")&& (securityInfo=="invalidSecurityAnswer")){%>
<tr class="LeftFrame" align="center">
<td height="7%"><font size="-1">Your Login Name or Company Id is incorrect. </font></td>
</tr>
<% }else if((loginInfo=="validLoginInfo")&& (securityInfo=="invalidSecurityAnswer")){%>
<tr class="LeftFrame" align="center">
<td height="7%"><font size="-1">Your Security Answer is incorrect. </font></td>
</tr>
<%}else{%>
<tr class="LeftFrame">
<td height="7%"><font size="-1"></font></td>
</tr>
<%} %>
<tr class="LeftFrame">
<td width="100%" height="25">
<table width="100%" border="0" class="LeftFrame">
<tr>
<td height="25%">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="25%">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="25%">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="25%">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td align="right">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td align="right">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<%if(usersVO!=null&&usersVO_security==null){ %>
<tr>
<td width="26%">&nbsp;</td>
<td width="24%" align="left">Login Name</td>
<td width="32%" align="right">
<input type="text"
name="loginName" size="26"
caption="Login Name" mandatory="true" value="<%=usersVO.getLogin()%>" readonly="readonly"/></td>
<td width="18%">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="left">Company ID </td>
<td align="right"><input type="text"
name="companyId" size="26"
caption="Company ID" mandatory="true" value="<%=usersVO.getCustomerName()%>" readonly="readonly"/></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="left">Security Question</td>
<td align="right"><input type="text"
name="securityQuestion" size="26"
caption="Secret Question" mandatory="true" value="<%=usersVO.getSecretQuestion()%>" readonly="readonly"/></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="left">Security Answer</td>
<td align="right"><input type="text"
name="securityAnswer" size="26"
caption="Secret Answer" mandatory="true" onblur="this.value=trimSpace(this.value)"/></td>
<td>&nbsp;</td>
</tr>
<%}
else
{
%>
<tr>
<td width="26%">&nbsp;</td>
<td width="24%" align="left">Login Name</td>
<td width="32%" align="right">
<input type="text"
name="loginName" size="26"
caption="Login Name" mandatory="true" onblur="this.value=trimSpace(this.value)"/> </td>
<td width="18%">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="left">Company ID </td>
<td align="right"><input type="text"
name="companyId" size="26"
caption="Company ID" mandatory="true" onblur="this.value=trimSpace(this.value)"/></td>
<td>&nbsp;</td>
</tr>
<%} %>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td align="right"><input type="submit" class="fbutton"
name="login" value="Submit" onclick="return submitCurrentForm('<%=EventConstants.VALIDATE_FORG OT_PASSWORD_EVENT%>');" /></td>[/HTML]
Jul 13 '07 #1
Share this Question
Share on Google+
8 Replies

acoder
Expert Mod 15k+
P: 16,027
You can't give focus to two textfields at the same time. It doesn't make sense.

If you type, it would have to enter in two fields at the same time!
Jul 14 '07 #2

gits
Expert Mod 5K+
P: 5,390
You can't give focus to two textfields at the same time. It doesn't make sense.

If you type, it would have to enter in two fields at the same time!
;) in case you want to have that behaviour simulated, for whatever reason that is useful ... use the keypress-event and always update the second field with the input of the first (focused) field where the user actually types in something ... ;))

kind regards
Jul 14 '07 #3

acoder
Expert Mod 15k+
P: 16,027
;) in case you want to have that behaviour simulated, for whatever reason that is useful ... use the keypress-event and always update the second field with the input of the first (focused) field where the user actually types in something ... ;))

kind regards
Yes, you're right, it's easy to simulate that behaviour, but it just doesn't make sense on any level to give two elements/items/anythings focus at the same time. Even two windows can't have focus at the same time.
Jul 16 '07 #4

gits
Expert Mod 5K+
P: 5,390
Yes, you're right, it's easy to simulate that behaviour, but it just doesn't make sense on any level to give two elements/items/anythings focus at the same time. Even two windows can't have focus at the same time.
i agree ... the sense of focus is to have a (one) control focused so that this control receives the users command ... i cannot see anything that overrides that rule ... except you want to have something synchronized ... may be in realtime and visualize that at the same time ... but that's a case for our 'simulating'-thing ...

kind regards
Jul 16 '07 #5

P: 12
i don't want to focus at a time i want to focus the fields depending on my conditions that i gave in if else block,go through my code once again

Thanks in advance
Jul 17 '07 #6

gits
Expert Mod 5K+
P: 5,390
[HTML]
...
onload="
document.forgotPassword.loginName.focus();
document.forgotPassword.securityAnswer.focus();
">
...
[/HTML]

this is not working ... or better ... it is but the first statement is useless ... your code will always set the focus to the 'securityAnswer'-field. when you in case you want it conditionally you have to put one to it ... something like:

Expand|Select|Wrap|Line Numbers
  1. //something is true
  2. if (something == true) {
  3.     field1.focus();
  4. } else {
  5.     field2.focus();
  6. }
  7.  
may be i don't really get the problem ... can you explain it in more detail? what is not working, and where do you need special help?

kind regards
Jul 17 '07 #7

P: 12
Hi Gifts ,
I think u couldn't catch my point exactly let me explain breifly,

I <body onload="focusFields()" >In Body onload i am calling this function.

In function i am writing condition like as u told
Expand|Select|Wrap|Line Numbers
  1.  fucntion focusFields()
  2. {
  3.           if(securityAnswer ! =null)
  4.           {
  5.                      document.forgotPassword.securityAnswer .focus();
  6.           }
  7.           else 
  8.           {
  9.                   document.forgotPassword.loginName.focus();
  10.           }
  11. }
  12.  
But my here is security Answer field is in if loop and loginName field is in else loop ..bcoz of this i could n't get both feild values at a time when comes loginName security Answer shows null only .....i need to get both values then only i check the condition in my javascript.....I think now u got it


Expand|Select|Wrap|Line Numbers
  1. <!-- In this if loop i have securityAnswer Field  -->
  2.   <%
  3.             if(usersVO!=null&&usersVO_security==null){ 
  4. %>
  5.                     <tr>
  6.                         <td width="26%">&nbsp;</td>
  7.                         <td width="24%" align="left">Login Name</td>
  8.                         <td width="32%" align="right">
  9.                       <input type="text"
  10.                             name="loginName" size="26" 
  11.                             caption="Login Name" mandatory="true" value="<%=usersVO.getLogin()%>" readonly="readonly"/></td>
  12.                         <td width="18%">&nbsp;</td>
  13.                     </tr>
  14.                     <tr>
  15.                         <td>&nbsp;</td>
  16.                         <td align="left">Company ID </td>
  17.                         <td align="right"><input type="text"
  18.                             name="companyId" size="26"
  19.                             caption="Company ID" mandatory="true" value="<%=usersVO.getCustomerName()%>" readonly="readonly"/></td>
  20.                         <td>&nbsp;</td>
  21.                     </tr>
  22.                     <tr>
  23.                         <td>&nbsp;</td>
  24.                         <td align="left">Security Question</td>
  25.                         <td align="right"><input type="text"
  26.                             name="securityQuestion" size="26"
  27.                             caption="Secret Question" mandatory="true" value="<%=usersVO.getSecretQuestion()%>" readonly="readonly"/></td>
  28.                         <td>&nbsp;</td>
  29.                     </tr>
  30.                     <tr>
  31.                         <td>&nbsp;</td>
  32.                         <td align="left">Security Answer</td>
  33.                         <td align="right"><input type="text"
  34.                             name="securityAnswer" size="26"
  35.                             caption="Secret Answer" mandatory="true" onblur="this.value=trimSpace(this.value)"/></td>
  36.                         <td>&nbsp;</td>
  37.                     </tr>
  38.                     <%}
  39. '
  40.  
  41.  
  42.  
  43. <!-- In this else loop i have loginName Field -->
  44.  
  45.   else
  46.                     {
  47.                     %>
  48.                     <tr>
  49.                         <td width="26%">&nbsp;</td>
  50.                         <td width="24%" align="left">Login Name</td>
  51.                         <td width="32%" align="right">
  52.                       <input type="text"
  53.                             name="loginName" size="26" 
  54.                             caption="Login Name" mandatory="true" onblur="this.value=trimSpace(this.value)"/>                  </td>
  55.                         <td width="18%">&nbsp;</td>
  56.                     </tr>
  57.                     <tr>
  58.                         <td>&nbsp;</td>
  59.                         <td align="left">Company ID </td>
  60.                         <td align="right"><input type="text"
  61.                             name="companyId" size="26"
  62.                             caption="Company ID" mandatory="true" onblur="this.value=trimSpace(this.value)"/></td>
  63.                         <td>&nbsp;</td>
  64.                     </tr>
  65.                     <%} %>
  66.                     <tr>
  67.                       <td>&nbsp;</td>
  68.                       <td>&nbsp;</td>
  69.                        <td align="right"><input type="submit" class="fbutton"
  70.                             name="login" value="Submit" onclick="return submitCurrentForm('<%=EventConstants.VALIDATE_FORGOT_PASSWORD_EVENT%>');" /></td>


Thanks in Advance
Jul 23 '07 #8

epots9
Expert 100+
P: 1,351
i'm trying to put all this together...from what i understood,

when the user clicks the submit button u want to give focus to 2 textfields (at the same time)...or do u mean make the textfields visible?
Jul 23 '07 #9

Post your reply

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