Could Not Set The Selected Property. Unspecified Error Ie6
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 comment here... Fill in your details below or click an icon to log in: Email (required) (Address never made public) Name (required) Website You are commenting using your WordPress.com account. (LogOut/Change) You are commenting using your Twitter account. (LogOut/Change) You are commenting using your Facebook account. (LogOut/Change) You are commenting using your Google+ account. (LogOut/Change) Cancel Connecting to %s Notify me of new comments via email. Archives July 2016(1) May 2016(1) March 2015(1)
one of your newly created items. I came across this while trying to use jQuery's .val() function to set the selected element after I had added some options to my select. Here's what's running on this page.: window.onload = function() { var select = document.getElementById('mySelect'); var option = document.createElement('option'); option.value = 'CA'; option.innerHTML = 'CA'; select.appendChild(option); // Just asking about the children kills it! select.childNodes; option.selected = true; }; This is the simplest repro I could make. Note that the https://punekaramit.wordpress.com/2009/12/15/ie6html-select-could-not-set-the-selected-property-unspecified-error/ error will only occur if you call appendChild, then ask for the select's childNodes, then set the selected property on the newly created option. If you set selected earlier, either before appendChild or after it, there's no problem. And if you omit childNodes, it works. The problem with jQuery is that its .val() function loops over childNodes looking for an https://benhollis.net/experiments/browserdemos/ie6-adding-options.html option to set, and thus always triggers the bug. If you wrap the code that sets selected in a setTimeout it works, surprisingly enough. I have to assume it needs to give control back to the browser to let state settle. Another way to get this to work is to wrap the code that sets selected in a try/catch block and just swallow the error from IE. It seems to set the element as selected properly despite the error! Yet another way to work around this appears to be to use setAttribute instead of setting the property directly. option.setAttribute('selected', true) causes no error. A sub-bug is that setting selectedIndex on the select element won't work to select the new option whether or not you've accessed childNodes. It doesn't cause an error, it just doesn't do anything. For example, I can set the selectedIndex to 1, which selects "PA", but not to 2, which would select my new option. I might break that out into a separate bug later. This has been fixed in IE7. Back to Browser Bugs
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us http://stackoverflow.com/questions/13549052/could-not-set-the-selected-property-unspecified-error-knockoutjs Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Could not set the selected property. unspecified error. knockoutJs could not up vote 6 down vote favorite I'm using VS2010 on windows XP, Jquery-1.7.1.min.js, knockout-2.1.0.js, my browser is IE8. trying to make a simple biding with array and : here is the code: //my.js: $(function () { function tvm() { // Array this.tickets = [ { name: 'A', price: 125 }, { name: 'B', price: 128 }, { name: 'C', price: 145 } ]; // this will hold could not set the selected value this.chosenTicket = ko.observable(); } ko.applyBindings(new tvm()); }); //html:
when running this I can see the select element with its data(until now everything good), when try to select a value from the select element I get the following error message: "Could not set the selected property. unspecified error" Any idea how to fix this problem?(couldn't find help on the forums), javascript jquery internet-explorer knockout.js share|improve this question edited Nov 25 '12 at 21:05 Tariqulazam 3,69711731 asked Nov 25 '12 at 7:11 MRK 334 1 Your code jsfiddle.net/baQxf/1 is working file on Win7 with using IE8. –nemesv Nov 25 '12 at 7:17 ... and Chrome, FireFox, IE - under windows 8. –ColinE Nov 25 '12 at 7:19 yes, I try it on win8 with chrom, safari, ie9, works great!! but with the winXP :( , maybe the org is running some kind of policy –MRK Nov 25 '12 at 7:23 I tried it with IE6 on XP with no error. I'll try IE8/XP when I get a chance. –Michael Best Nov 26 '12 a