+ 1

Onmouseover / onchange with <select>

<select> <option value="uk">UK</option> <option value="us">US</option> <option value="ch">China</option> </select> when user puts his mouse over any of the above country, a submenu should appear containing 3 cities of that country (it must be done via "onmouseover" / "onchange" events) and i have no idea how to do that. How to do that?

8th Mar 2018, 8:46 PM
Farhan Farooq
Farhan Farooq - avatar
9 Answers
+ 4
Then I guess you have to put onmouseover which will run a js code for changing the look. Make like a list of options and add "display=none" and when mouse moves over change it to "display=inline". I'm sorry if you don't understand it and I can't show you on an example right now. I will ask someone else to help you.
8th Mar 2018, 7:30 PM
Tim Thuma
Tim Thuma - avatar
+ 4
as HTML attribute: onmouseover="myFunction()" js: function myFunction() { document.[targetselectsubclassorid].style.display = "show". Make sure each class or id is hidden by default and only targeted under the conditions you want.
8th Mar 2018, 7:40 PM
Peter David Carter
Peter David Carter - avatar
+ 4
onmouseover is a pain to work with so I'd use onchange. Once the country is selected, you get called. Here is an example of that. https://code.sololearn.com/W16sY9vEuIk3 The displaying your cities is a different matter. I've never done it. However, I would start with this alert and modify it so it only shows onmouseover. https://code.sololearn.com/WaB2vCB0urR1
8th Mar 2018, 8:31 PM
John Wells
John Wells - avatar
8th Mar 2018, 7:40 PM
Peter David Carter
Peter David Carter - avatar
+ 3
This might be close. I don't have access to my laptop to test it, but works okay on my phone. https://code.sololearn.com/WTtQhNL5S1nW
8th Mar 2018, 9:40 PM
John Wells
John Wells - avatar
+ 3
@John Wells the solution seems good, but does it need that many lines?
8th Mar 2018, 9:43 PM
Peter David Carter
Peter David Carter - avatar
+ 2
Here's an example for a dropdown menu. https://code.sololearn.com/W5qaHpzq0cBi/?ref=app If you also want to display cities just a div where cities will display.
8th Mar 2018, 7:14 PM
Tim Thuma
Tim Thuma - avatar
+ 2
Most likely not. I haven't spent time to understand Calvin's code as yet, but I'm sure things can be removed.
8th Mar 2018, 10:01 PM
John Wells
John Wells - avatar
+ 1
I would like to get it done via <select> <option value="uk">UK</option> <option value="us">US</option> <option value="ch">China</option> </select> when user puts his mouse over any of the above country, a submenu should appear containing 3 cities of that country (it must be done via "onmouseover" / "onchange" events).
8th Mar 2018, 7:23 PM
Farhan Farooq
Farhan Farooq - avatar