javascript - Select already selected item in dropdown/select - list -


i've been searching answer question quite time now, no luck, or buggy solutions @ max.

the problem im facing have select element (obviously) doesn't fire "onchange" event when selecting selected item.

like this:

<select onchange="alert(this.value);"> <option>1</option> <option>2</option> <option>3</option> </select> 

now, select item 1 first. afterwards need able select item 1 again.

this feature extremely important success of project i'm working on.

any appreciated.

edit: (more info)

this functionality needed im working on project google maps users presentet dropdown jump country (eg select "spain" in dropdown, google maps sets spain view.

the problem comes when want go spain, drag around map, , end in italy. want go spain, cant select dropdown until select else first. boss doesn't :)

edit2: solution

so theres few solution. 1 of them throw action onblur (when unfocusing control) could work, blur list onchange, still people selecting same item again, trigger blur control wont go, , unless switch focus them self, wont see changes map.

still cannot understand why should hard find event excutes on option select / click / blur or whatever.. ill keep looking myself, , check here tad later.

edit 3: final solution

right managed working, not ment be, close enough, atleast anyways.

the solution came add "please select country" option @ top of select. on change, change text, , value of "please select country" of selected item, , reset selectedindex 0. way, when selecting, say, spain, @ top of list in disabled state, , further down in working state. can click spain in middle of list go spain though still selected (the top item is)

quite neat, idea supplied coworker.

script following:

   var dummyoption; function setdummycountry(obj) {     var selectedoption = obj.options[obj.selectedindex];     if (dummyoption != null) {         dummyoption.text = selectedoption.text;         dummyoption.value = selectedoption.value;     }     else {         dummyoption = document.createelement("option");         dummyoption.text = selectedoption.text;         dummyoption.value = selectedoption.value;         dummyoption.setattribute("disabled", "true");         obj.options[0] = dummyoption;     }     obj.selectedindex = 0; }  <select onchange="setdummycountry(this);">     <option value="">please select country</option>     <option value="es">spain</option>     <option value="se">sweden</option>     <option value="no">norway</option> </select> 

i hope someone!

and tried me thank ideas , time.

i think there no way change event gonna fire if same item selected. facing same issue did simple usability hack: when item selected show user item selected in span , reset value of dropdown default value (--select--).

hth


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -