Forum Moderators: open

Message Too Old, No Replies

I'm trying to biuld an Dynamical Focusfunktion

         

kornix

9:13 am on Apr 22, 2005 (gmt 0)



Hello there,

I am programmer but not in JavaScript, however it seems to be the best way to get a solution within my project. I need a dynamical setFocus-Function, what seems to be pretty easy but I don't find the correct syntax. -It should look like this:


<script language="javascript">
function setFocus(ctrlID){
document.forms[0].ctrlID.focus();
}
</script>

<body>
<FORM ...>
<INPUT id="TBFA" ...>
<INPUT id=...onchange="javasript:setFocus(TBFA);">
</FORM>
</body>

Can anyone help?

thanx - Peter

Bernard Marx

12:24 pm on Apr 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1)
javasript --> javascript (!)
The javascript pseudo-protocol is not needed in event handlers anyway.
Scrap it.

2)
setFocus(TBFA)

The argument is a string (since is an id)
Quote it.

3)
document.forms[0].ctrlID.focus();

To put arbitrary memberNames in member chains, use []:
document.forms[0][ctrlID].focus();

It may be better to either
a) Change the id attribute to a name attribute
b) Use getElementById instead

document.getElementById(ctrlID).focus()