onclick or onmouseover will change focus to...

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
valen53
Forum Contributor
Posts: 137
Joined: Tue Aug 27, 2002 9:29 am

onclick or onmouseover will change focus to...

Post 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
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

Can we see some sample code?
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post 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>
valen53
Forum Contributor
Posts: 137
Joined: Tue Aug 27, 2002 9:29 am

Post 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
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post 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.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

id

Post 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
Post Reply