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


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.