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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you determine focus with an if statement?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am having an issue wherein I have two forms. While normally, if you hit enter, it automatically clicks submit for you (in IE) this does not happen when you have a select box selected... to fix this I created the following script:

<script language = javascript>
function document.onkeydown()
{
if(window.event.keyCode == 13) {
document.form1.submit();
}
}
</script>

Now this works great when there is only one form... however on this page there are two. As a result I want to add if statements to that so that it determines which select box has the focus, then performs the appropriate function... the unfortunate thing is that the select boxes have the exact same name, like so:

<form name=&quot;form1&quot;>
<select name=&quot;select&quot;>
</select>
</form>

<form name=&quot;form2&quot;>
<select name=&quot;select&quot;>
</select>
</form>

I thought that code like the following would work:

If(form1.select.focus=true){
function
}

However this has not proved fruitful... any ideas? This is targeted specifically at IE, Opera and Netscape are not a concern at this point, however they may be in the future.
 
try using a name other than &quot;select&quot; even select1, select2 etc. I belive that &quot;select&quot; is a reserved term in IE DOM, but it won't throw an error, since you have the select element in your forms. &quot;The surest sign that intelligent life exists elsewhere in the universe is that it has never tried to contact us&quot;
Bill Watterson, Calvin & Hobbes
 
Bentley22 is probably on the right track. I'll repeat what I've said many times in this forum:

NEVER use a reserved word for the name of ANYTHING!

Also, do NOT use the same name for a form element and a function, or anything like that. Make sure ALL names are unique.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Actually it wasn't named select, I just didn't want to paste the code there and typed that out in quick pseudocode. The actual name was something entirely different. <smiles> And while I wish that all names were unique, the two forms share the same name for their select box but this is because both forms on the page share the same submit script... (yes, I find problems with this too but it is someone else's decision and I am working within their constraints). Anyway, when you submit it takes the value of the submit for that form... so I had to diferentiate between submits by putting the appropriate form. in front of it...

Oh well, it works now, so all is well. <smiles>
 
Glad you found a way to make it work. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Thanks.

<feeds you other crunchy things that are good with mustard that I may be spared the fate>

I ended up setting a variable in the onfocus for each and when that variable was == to one thing submit form 1, and submit form 2 for the other thing. <smiles>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top