henke Posted October 4, 2006 Share Posted October 4, 2006 Hi!When a user change month for example from February to Mars, i want to add nr of days in options. It works in ie, opera, but not in Firefox.My main question is.. Is there an easy way of adding options in compatible mode that works for all browsers?i get this message in firefox consolens_error_xpc_not_enough_argsFel: uncaught exception: [Exception... "Not enough arguments [nsIDOMHTMLSelectElement.add]" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame :: theurl :: line 1111" data: no]my function call looks like thisfunction changeSelectOptions(){var userselectedYearMonth=document.getElementById("selectYearMonth").value;var year=userselectedYearMonth.substring(0,4);var month=userselectedYearMonth.substring(5);DaysObject=document.getElementById("dateselect");CurrentDaysInSelection = DaysObject.length;DaysForThisSelection = DaysInMonth(month, year); if (DaysForThisSelection > CurrentDaysInSelection) { for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++) { NewOption = new Option(DaysObject.options.length + 1); DaysObject.add(NewOption); } } } Link to comment Share on other sites More sharing options...
Chocolate570 Posted October 5, 2006 Share Posted October 5, 2006 First of all, I'm not sure if this is a select box you're trying to find:var userselectedYearMonth=document.getElementById("selectYearMonth").value;and if it is, then the proper syntax is this:userselectedYearMonth=document.getElementById("selectYearMonth");userselectedYearMonth=userselectedYearMonth.options[userselectedYearMonth.selectedIndex].value;And that would return the value of your selected option.Also!The reason that error is popping up is that you're missing a parameter in your select.add(). FireFox will give an error if both parameters are not there. It doesn't matter whether one is null or not though.You have to give both of these parameters:select.add(element to add,element to put it before)If you put "null" in element to put it before it sticks it self at the end of the list. :)Hope that helps. It should clear up your error. :)Choco Link to comment Share on other sites More sharing options...
henke Posted October 5, 2006 Author Share Posted October 5, 2006 i tried to add "null", but i get another exception. Fel: uncaught exception: [Exception... "Could not convert JavaScript argument arg 1 [nsIDOMHTMLSelectElement.add]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: .....I liked firefox but... (It seems that Firefox read w3c recommendations but no other web browser vendor did. i must say that firefox seems to take w3c recommendations to serously. Why not do as the all other browser vendors.)If firefox will implement a more complex way to do things developers will give up to fix the problems for this browser and the user with a broken page.. Link to comment Share on other sites More sharing options...
jesh Posted October 5, 2006 Share Posted October 5, 2006 This tutorial (http://www.mredkj.com/tutorials/tutorial005.html) uses a try/catch block to attempt to add the option one way for standards compliant browsers and another for IE. It might help. Link to comment Share on other sites More sharing options...
henke Posted October 5, 2006 Author Share Posted October 5, 2006 Well you where right but i misunderstood you.. Thanks :)try { DaysObject.add(NewOption,null); // firefox solution } catch(ex) { DaysObject.add(NewOption); // All browsers except firefox } Link to comment Share on other sites More sharing options...
henke Posted October 5, 2006 Author Share Posted October 5, 2006 This tutorial (http://www.mredkj.com/tutorials/tutorial005.html) uses a try/catch block to attempt to add the option one way for standards compliant browsers and another for IE. It might help.In this case you are not right. IE and most modern browsers do this in one way. Firefox has done this according to w3c recommendations. Thanks for the url. That solved my problem. /Henrik Link to comment Share on other sites More sharing options...
jhecht Posted October 6, 2006 Share Posted October 6, 2006 im not sure about this, but i think that even in IE and so on, you should be able to use the DaysObject.add(NewOption,null); because the function exists in both of them, just firefox has stricter guidlines for them, so even though IE says "eh its ok its only missing an argument" firefox goes "###### no, we need an argument or NO DEAL". Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now