Friday, 15 June 2012

javascript - How to copy selection from one select to another? -


I have two selected elements, with the same option, and the same value for these options, but different (translated) text

How can I copy selection from each other?

From a user's perspective, if a person is "red" (value = 1) and "gray" (value = 1) and "rufum" (value = 5) " (value = 5)

& lt; Input & gt; For the tag, this works:

  $ (this) .closest ('.magic-guardian') .fund (".in common identifier"). No (this) .val ($ (this) .val ());   

Unfortunately, it omits & lt; Select & gt; tag.

I found several ways to copy the item, but there can be no way to make a copy of the actual selection.

Edit:

EDIT: If possible, I want to work for both single and multilevel. I know first that I have not regretted in my Bela.

& lt; Select & gt; Elements have a property selectedIndex which indicates which of their options are selected.

If you see selectedIndex << code> a & lt; Select & gt; , then selected index to other and select & gt; Set to , you should get the result you are looking for. / P>

However, if your & lt; Select & gt; Accepts multiple selections (as your question means), so this is a bit more tedious. & lt; Options & gt; You must loop through the elements and each has to see if this selected property is true or not.

(This is why jQuery popular: JavaScript DOM interface is often useless .)

No comments:

Post a Comment