Could Not Set The Selected Property Unspecified Error
the HTML select boxes are populated with option elements on the fly within jQuery’s $(document).ready() function. It worked perfectly fine in all the browsers ( Firefox , Google Chrome and IE7) except IE 6. I was fortunate enough to find this FINE article that enlightened me about the error and fix for it. jquery-ie6-and-could-not-set-selected.html Thanks a ton to the Author of above blog. Here are the details of problem faced and resolution I used based on the above article/blog. Upon checking the JavaScript error for IE 6, found that it threw the following error Error: Could not set the selected property. Unspecified error. This was not caused due to Java Script programming error while initializing the SELECT boxes with OPTION elements. This was caused by the line that actually sets the selected item in the HTML SELECT using //Consider a HTML SELECT control with id=”source” in HTML page. $("#source").val($("option[index=0]","#source").val()); To resolve this error put the code that selects the value in a try/catch block. For IE6 once this line throws the exception again try to set the selected value using JavaScript function “setTimeout()” with a timeout period of 1 millisecond. This much time-delay is sufficient for IE6 to see the refreshed DOM tree and select the corresponding item. //Consider a HTML SELECT control with id=”source” in HTML page. try { $("#source").val($("option[index=0]","#source").val()); } catch(ex) { setTimeout(function() { $("#source").val($("option[index=0]","#source").val());},1); } Share this:ShareLinkedInFacebookGoogleLike this:Like Loading... Related This entry was posted on Tuesday, December 15th, 2009 at 1:45 PM and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site. Post navigation « Previous Post Next Post » One Response to IE6/HTML Select - ‘Could not set the selected property. Unspecifiederror.' feroz says: April 19, 2010 at 4:41 AM Thanks!!!! Reply Leave a Reply Cancel reply Enter your
Navigation ← Previous TicketNext Ticket → Opened 9 years ago Closed 3 years ago #2252 closed bug (fixed) Setting select value via val() shows error in IE6 Reported by: zaadjis Owned by: flesler Priority: low Milestone: 1.11 Component: attributes Version: 1.4.4 Keywords: ie6, select, val Cc: Blocked by: Blocking: Description When a select element is filled (dynamicly) with options and then one tries to set a selected option an error is thrown in IE6: "Could not set the selected property. Unspecified error.". https://punekaramit.wordpress.com/2009/12/15/ie6html-select-could-not-set-the-selected-property-unspecified-error/ This seems to be some timing issue, because inserting some delay (timeout, alert, etc.) before the val() call, the error doesn't occur. Oldest first Newest first Threaded Comments only Change History (17) comment:1 Changed 9 years ago by dalangalma I tried your patch, and while it works for me using your test case, it still https://bugs.jquery.com/ticket/2252 core-dumps the browser on my app. I'll try to distill mine into a minimal test case at some point, but it'll be difficult. The function that's killing things looks like this: // select is a DOM element, versions is an array of strings, selectedOption is a string function fillSelect(select, versions, selectedOption) { // Map each version string to a DOM element var newOptions = $.map(versions, function(version, i) { return $("") .val(version) .text(version) .get(0); }); $(select).append($(newOptions)) .val(selectedOption); } I'm not sure if it matters, but my page is in "quirks" mode. comment:2 Changed 8 years ago by flesler Milestone changed from 1.2.3 to 1.2.4 Owner set to flesler Status changed from new to assigned I really don't get this. You do .val(2) and there's no option with value="2". Don't you mean $('select').attr('selectedIndex',2) ? That will surely work with the modified recently .attr(). If that was the case, please close the ticket as invalid. comment:3 Changed 8 years ago by flesler Milestone changed from 1.2.4 to 1.
error.' I was trying to do this with JQuery - imagine htmlOptions is a client-side cache of option values to put in a select box, ctrl is the id of the box, and id is the current selected http://csharperimage.jeremylikness.com/2009/05/jquery-ie6-and-could-not-set-selected.html value: function loadDropDown(htmlOptions, ctrl, id) { $(ctrl).html(htmlOptions); $(ctrl).val(id); } It worked great on everything http://www.codeproject.com/Questions/279839/answer.aspx but IE 6.0. Then I got the big, fat "Could not set the selected property. Unspecified error." Turns out there is a little bit of a timing issue with the DOM. After scouring the 'net for solutions, I finally settled on this as my favorite - no crazy browser hacks to determine the type and version, IE could not 6.0 gets the short end of the stick as it deserves: function loadDropDown(htmlOptions, ctrl, id) { $(ctrl).html(htmlOptions); try { $(ctrl).val(id); } catch(ex) { setTimeout("$('" + ctrl + "').val('" + id + "')",1); } } It's just enough delay to let the DOM settle and not complain. Posted by Jeremy Likness Email ThisBlogThis!Share to TwitterShare to Facebook Labels: dropdown, ie 6.0, jquery, select, unspecified error C#er : IMage Blog by Jeremy Likness could not set is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.Based on a work at csharperimage.jeremylikness.com. 18 comments: dromfijJune 22, 2009 at 10:38 AMGood Stuff! I had a similar bug and found this post via google search. Saved the day for me. Thanks :)ReplyDeleteAnonymousAugust 18, 2009 at 12:45 PMHey, this saved my day (well, rather my evening) as well :) Thanks!ReplyDeleteAnonymousAugust 24, 2009 at 6:27 PMThanks!! I am happy to see I was not the only one with this bug.ReplyDeleteEvan FreemanSeptember 4, 2009 at 2:49 PMWow I never would have guessed at this issue. Nice work finding the fix works a treat.ReplyDeleteKishore VemuriSeptember 15, 2009 at 9:28 AMHey Thank you very much. That saved lot of time. Really helped a lot.ReplyDeleteAnonymousOctober 2, 2009 at 1:13 PMthanks. This helped me out as well. My problem was a little bit different:MyJqueryObj.attr('selected','selected'); was giving me the error.to fix it, I put the command in a try block and had a catch block with nothing in it. With this change, the option was selected correctly and I didn't get an error.ReplyDeleteAnonymousOctober 6, 2009 at 11:38 AMThank you very mush! I lost one day, finding solving of this problem.ReplyDeleteMichael MahemoffNovember 1, 2009 at 4:06 PMNice, simple, workaround, thanks.I'd suggest a couple of minor improvements.(a) in most cases,
Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your Blog quick answersQ&A Ask a Question View Unanswered Questions View All Questions... C# questions Linux questions ASP.NET questions SQL questions VB.NET questions discussionsforums All Message Boards... Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ / MFC> ATL / WTL / STL Managed C++/CLI C# Free Tools Objective-C and Swift Database Hardware & Devices> System Admin Hosting and Servers Java .NET Framework Android iOS Mobile SharePoint Silverlight / WPF Visual Basic Web Development Site Bugs / Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase Research Library CodeProject Stuff communitylounge Who's Who Most Valuable Professionals The Lounge The Insider News The Weird & The Wonderful The Soapbox Press Releases Non-English Language > General Indian Topics General Chinese Topics help What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum Site Map Advertise with us About our Advertising Employment Opportunities About Us htmlfile:Could not set the selected property.Unspecified error in javascript Ask a Question All Questions All Unanswered FAQ Mohankumar.Engain asked:Open original thread dear sir, "html file: Could not set the selected property. Unspecified error" MY Code is, function setSelectedIndex(s, v) { for (var i = 0; i < s.options.length; i++) { if (s.options[i].text == v) { s.options[i].selected = true; return; } } But IE browswer can't supported. because error display. (other browsers are working well). Note: name : textbox Address : textbox City : Dropdown list Area : Dropdown list ------------------>Error is here(editing time) this error arise when I am editing customer details. Tags: Javascript B I U S small BIG