user2563256
user2563256

Reputation: 187

Not able to set value of drop down in jquery mobile

I am setting the value in drop down But it in not inserting .Why ? But same thing i do in another example i am getting the result.

 <div data-role="fieldcontain">
                        <label for="text-12" style="text-align:left;margin-left: 0px;"> Font Type:</label>
                        <select name="select-choice-1" id="select-choice-1" class="fontFamily_h">
                            <option>Select Font </option>
                            <option value="AntiquaAntiqua">AntiquaAntiqua</option>
                            <option value="Arial">Arial </option>
                           <option value="Times New Roman">Times New Roman</option>

                        </select>
                    </div>
<div data-role="fieldcontain">
                        <label for="text-12" style="text-align:left;margin-left: 0px;">Font Size:</label>
                        <select name="select-choice-1" id="select-choice-2" class="fontSize_h">Select Size
                            <option>Select Size</option>
                            <option value="9">9 px</option>
                            <option value="10">10 px</option>
                            <option value="11">11 px</option>
                            <option value="12">12 px</option>
                            <option value="13">13 px</option>

                        </select>
                    </div>


    $(document).on('click', '.default_h', function(event) {
       var i =12;
        alert("Hi"+ $('#select-choice-2').val()); getting select Size
       $('#select-choice-1').val('Arial').selectmenu("refresh");
       $('#select-choice-2').val('12 px').selectmenu("refresh");
        alert("Hi"+ $('#select-choice-1').val());  getting Arial
           alert("Hi"+ $('#select-choice-2').val());;getting select Size


});   

I am getting Arrial But in second example i am not getting 12 px

Upvotes: 0

Views: 822

Answers (1)

CodingIntrigue
CodingIntrigue

Reputation: 78595

You need to set the val() property to the actual value attribute, not the text:

$('#select-choice-1').val('Arial').selectmenu("refresh");
$('#select-choice-2').val('12').selectmenu("refresh");

Upvotes: 2

Related Questions