justinh Posted August 27, 2009 Share Posted August 27, 2009 Hey I'm trying to add an option to a select with Ajax. My code works fine in IE, but does not work in Firefox. I was going to post this in the AJAX section, but I'm pretty sure the problem is not AJAX, but is the way I'm going about adding an option to the select. I've tried pretty much everything I saw when looking the problem up on google. But still nothing. =( Here's the code in question function updateCountry(){ var region = document.getElementById("region"); var regionsel= region.options[region.selectedIndex].value; var url = 'http://cwwebapps.craneww.com/Agents/templates/testings.pl?region=' + regionsel; var myAjax = new Ajax.Request( url, { method: 'get' onSuccess: function(transport){ var countries = transport.responseText; var singlecountry = countries.split('|'); singlecountry.pop(); var theSelectList =$('country'); var select = document.forms.addentry.elements.country; theSelectList.options.length = 1; for(i=0;i<singlecountry.length;i++){ select.options[select.options.length] = new Option(singlecountry[i], singlecountry[i]); } }}); } You can see, http://cwwebapps.craneww.com/Agents/index2.pl?display=add_entry .. works in Internet Explorer, but no Firefox. Any help would greatly be appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
justinh Posted August 27, 2009 Author Share Posted August 27, 2009 allright I fixed it somehow function updateCountry(){ var region = document.getElementById("region"); var regionsel= region.options[region.selectedIndex].value; var url = 'http://cwwebapps.craneww.com/Agents/templates/testings.pl?region=' + regionsel; var myAjax = new Ajax.Request( url, { method: 'get', onSuccess: function(transport){ var countries = transport.responseText; var singlecountry = countries.split("|"); singlecountry.pop(); var select = document.forms.addentry.elements.country; select.options.length = 1; for(i=0;i<singlecountry.length;i++){ select.options[select.options.length] = new Option(singlecountry[i], singlecountry[i]);. } }}); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.