Click to See Complete Forum and Search --> : trouble with focus


___
05-03-2006, 11:02 AM
I want focus to stay in the input box called SERVICE when variables II and UPTO in the javascript g() are equal. I can't get it to work-the focus goes to the submit button STRY2. This part is at the end of the g().

Trim() and date_onkeydown() are javascripts I got from others.

Sorry can't get indenting to show here.
--------------------------------------------------------------------------
...
function g(dt,srv,maxrecs,maxrecs2) /*srv_,srvsrv_ used in here but not passed in*/
{
var dc=new Date(2006,7-1,1)
,df=new Date(parseInt(dt.value.substr(6,4),10),parseInt(dt.value.substr(0,2),10)-1,parseInt(dt.value.substr(3,2),10))
,srv=srv.value.toUpperCase()
,dbfarr=''
,upto=0;
if (dc>df)
dbfarr='srv_'
else
dbfarr='srvsrv_';
eval('upto='+dbfarr+'.length');
for (ii=0;ii<upto;ii++)
{
eval('document.write('+dbfarr+'[ii][0])');
document.write('<br>');
if (eval('trim(srv)=='+'trim('+dbfarr+'[ii][0])'))
break
};
alert(ii.toString()+' '+upto.toString());
if (ii==upto)
{
alert('got here');
srv.focus() /* also tried testform.elements[1].focus()*/
}
}
...
<body onLoad="testform.elements[0].focus()">
<cfoutput>
**
</cfoutput>
<cfset a=true>
<form name="testform" action="try2.cfm" method="post">
<input name="txtdate" type="text" ID="txtDate" size="10" maxlength="10"
onkeydown="date_onkeydown()" value="mm/dd/yyyy">
<input name="service" type="text" size="4" maxlength="4"
<cfoutput>
<cfif a>
onBlur="g(testform.elements[0],this,#qrecs#,#qrecsqrecs#);"
</cfif>
</cfoutput>>
<input name="stry2" type="submit" value="*">
</form>
</body>
...

Thankyou very much.

slaughters
05-03-2006, 11:57 AM
Add ID="" to each input tag. Keep the NAME="" there, but the ID is required by javascript to understand which input field you are talkng about.

I typically always use both, giving them both the same value. Some browsers will not be able to pick up the submitted form fields unless the NAME is there to identifiy them.