Pergunta

During my searching, I would like your help, ideas about this subject.

I have a button and when I click It. It triggers the opening of a popup with a combo box : Actually It works.

Now when I click in this button, I would like open the popup - AND - select a value automatically in the combo box.

I think use JQUERY with onClick event :

<div class="col-xs-6">
                                <select class="form-control" checked id="user.object" name="user.object">
                                    <option selected value="">choisir l'objet de votre demande *</option>
                                    #foreach($k in [1..$!localization.funnel.form.contact.object.size()])
                                        <option value="$k">$!localization.funnel.form.contact.object.get("$k").text</option>
                                    #end
                                </select>
                            </div>

It is the correct choice? Please let me know If I am right and give me some information if you want.

Thanks,

Ale.

Foi útil?

Solução 3

In fact, I found It !

if($(this).hasClass('bug'))
        $('#object option[value="4"]').prop("selected", true);

bug : the name of my tab object : I rename the name of my previous ID :

user.object

to :

object

because JavaScript doesn't like the dot "." in the ID name ! So

<select class="form-control" checked id="***object***" name="user.object">
                                    <option selected value="">choisir l'objet de votre demande *</option>
                                    #foreach($k in [1..$!localization.funnel.form.contact.object.size()])
                                        <option value="$k">$!localization.funnel.form.contact.object.get("$k").text</option>
                                    #end
                                </select>

Ale

Outras dicas

in your event handler that opens the popup add this line

$("#mySelect option").eq(2).prop("selected",true);

eq == zero-based index of the <option>s

https://api.jquery.com/eq/

demo : http://jsfiddle.net/53KBw/

Maybe this is what you want?

$('select option[value="SEL1"]').prop("selected",true);

Where SEL1 is the value of the option you want to select.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top