Page 1 of 1

onclick or onmouseover will change focus to...

Posted: Mon Jun 09, 2003 1:54 am
by valen53
i got question about java script.

i got a page contain few of button and list menu. i hope that when i mouseover or change the list menu. the focus will be change to the button beside the list menu. so when press enter, it will not press the first button.

anyone can give me some comment ?
thank u

Posted: Mon Jun 09, 2003 4:51 am
by qartis
Can we see some sample code?

Posted: Mon Jun 09, 2003 6:48 pm
by qartis
When I read that, I picture a dropdown menu, and a button beside it. When the user selects something from the dropdown menu, you want the button to become active, so the user can press [Enter] and submit the form? Try something like this:

Code: Select all

<form name=form1 action=script.php method=GET>
<select name=dropdown_menu onchange="document.form1.button1.focus();">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<input type=submit name=button1 value="Go">
</form>

Posted: Mon Jun 09, 2003 8:06 pm
by valen53
thank a lot .... i solve the problem...

but one thing is " document.form1.button1.focus();" , it make focus on the button1 , right. is it the ID will affect the action.

i mean
<input name="supplierbtn" type="submit" id="supplierbtn" value="List">

<input name="customerbtn" type="submit" id="supplierbtn" value="List">

if ID is same name, java script error will occur

Posted: Mon Jun 09, 2003 11:24 pm
by qartis
The ID can be the same, because you can focus() a button by its name, and those two buttons' names are unique, so that should work.

id

Posted: Tue Jun 10, 2003 12:30 pm
by phpScott
The only problem will occur if you try to use javaScripts getElementById() as you have to items with the same Id this will confuse javaScript.
But if you are not using getElementById then no worries.

phpScott