Jump to content

adding option to select


justinh

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/172148-adding-option-to-select/
Share on other sites

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]);.
                                             }
                                      }});
}


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.