Busted Mug

A blog that documents solutions to the most frustrating problems that occur during development in technologies such as Java, XML, AJAX, SQL, CSS and others that make me want to throw my coffee mug against the cube wall.

Thursday, November 30, 2006

Select boxes and "Could not convert JavaScript argument" (NS_ERROR_XPC_BAD_CONVERT_JS)

While trying to add a dynamically generated option to a select box I ran into this error:
Error: uncaught exception: [Exception... "Could not convert JavaScript argument" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: file:///C:/Documents%20and%20Settings/mmbmb/Desktop/calendar%20de3v/calendarDateInput.js :: PickDisplayDay :: line 148" data: no]
I was perplexed for some time until I did a little research and ran into this page on Quirksmode. The solution lies here:
 for(i=0;i<list.length;i+=2)
 {
  box2.options[i/2] = new Option(list[i],list[i+1]);
 }
I was trying to call the .add method of a select using text as an argument. This is non-standard (but I think works in IE). You have to instantiate an option object or else JS will error while trying to convert. Quirksmode is great btw.

2 Comments:

At 8:02 PM, Anonymous Anonymous said...

Thanks for the tip. I'm not a regular developer, and was using the IE method without realizing it. Guess it really is more intuitive!

 
At 5:57 AM, Blogger Keeper said...

This comment has been removed by the author.

 

Post a Comment

<< Home