views:

41

answers:

1

A kinda funny problem, im doing a .clone() on a select-element (for preview purpose) and the selected value isnt transferred. I.e my solution is to set selected="selected" on selectbox change.

But, i can't get it to work in any form. Ideas?

$("select").change( function() { 
  $(this).find("option:selected").attr("selected", "selected");
});
A: 

$(this).find("option:selected").attr("selected", "selected"); you are looking for the selected then change it to selected? hmmmm it doesn't make sense ;)

how about try something like this, $(this).find("option").eq(1).attr("selected", "selected");. This will make 2nd option selected

Reigel
Well, my problem isnt the select part, its setting selected="selected" to the value currently being selected (puh, loads of selects). Your code only slects the second option - no matter what i want to select.
Anjoh
I was giving you the idea. `$(this).find("option:selected")` gets the `option` which is `selected`. So, you don't have to set it to `selected`. My example just show one way of how to change the 2nd being selected. If you use, `eq(3)`, then the 4th will be `selected`. or if you use `$(this).find("option").last().attr("selected", "selected")`, last will get `selected`.
Reigel