Solved

FireFox 33.0.3 and Input Type Select option:selected Not Working?

Posted on 2014-11-07
12
567 Views
Last Modified: 2014-11-13
I need to 'reset' all the dropdowns on a form showing in Jquery-ui dialog.
The following code works with Chrome 38.0.2125.111 and IE 11.0.9600.17358 but NOT with FireFox 33.0.3...
I have two code examples and only use one and comment-out the other. Just wanted to show both...

[Jquery UI Dialog]
var $dialog = $('#myModal').dialog(
         {
             autoOpen: false,
             open: function (event, ui) {

             },
             close: function (event, ui) {
                 $('#form1 select option:first-child').attr('selected', 'selected');

                 $("#form1 select").each(function ()
                 {                     
                     $(this).find('option:first-child').attr("selected", "selected");
                 });
             },
             buttons: [
                 {
                     text: "Clear All",
                     width: "100",
                     click: function () {
                         $('select option:first-child').attr('selected', 'selected');

                         $("#form1 select").each(function () {
                             $(this).find('option:first-child').attr("selected", "selected");
                         });
                     }
                 }
             ]
         });

 <div id="myModal">
                <div>
                    <div>
                        <div>
                            <form id="form1">
                                <div class="form-group">
                                    <div class="col-sm-4">
                                        <label class="col-sm-3 control-label">Class</label>
                                        <select class="form-control" id="class" name="class">
                                            <option value="class">Any</option>
                                            <option value="class">Article</option>
                                            <option value="class">Conjunction</option>                                           
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4">
                                        <label class="col-sm-3 control-label">Case</label>
                                        <select class="form-control" id="case" name="case">
                                            <option value="case">Any</option>
                                            <option value="case">Accusative</option>
                                            <option value="case">Dative</option>                                            
                                        </select>
                                    </div>
                                </div>
                           </form>
                        </div>
                    </div>
                </div>
            </div>

Open in new window

0
Comment
Question by:WorknHardr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 40429650
use :
                click: function () {
                         $("#form1 select").val("");

                     }
0
 

Author Comment

by:WorknHardr
ID: 40429752
That works too good, I need the first option to display in each dropdown. Sorry I didn't specify on original post ;)
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40429758
and what did you get?
0
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 

Author Comment

by:WorknHardr
ID: 40429761
All selects have blank text area, but dropdown values show on dropdown open.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40429770
which line is the blank area here ?
<select class="form-control" id="class" name="class">
                                            <option value="class">Any</option>
                                            <option value="class">Article</option>
                                            <option value="class">Conjunction</option>                                           
                                        </select>

Open in new window

0
 

Author Comment

by:WorknHardr
ID: 40429792
Line one, all elements show text when click down arrow.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40429795
I don't understand what you mean
I think you should open a new question and close this one as your initial requirement (resetting a dropdown) work fine in firefox now
0
 

Author Comment

by:WorknHardr
ID: 40429811
How bout this: $("#form1 select").prop('selectedIndex', 0);
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40430013
what is the difference?
0
 

Accepted Solution

by:
WorknHardr earned 0 total points
ID: 40430175
Since jquery 1.6 prop (property) and attr (attribute) are divided and no longer in the same attr object. I changed my original code to use prop and now it works in Firefox too.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40430199
ok.
0
 

Author Closing Comment

by:WorknHardr
ID: 40439492
Found answer myself
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question