Solved

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

Posted on 2014-11-07
12
522 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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

803 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