Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6831467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:44:27+00:00 2026-05-26T22:44:27+00:00

Is this possible? If so, I could really use some help on this. I’m

  • 0

Is this possible? If so, I could really use some help on this. I’m very new to JavaScript and thus hardly know any of the syntactical specifications, nor proper methodology.

Some functions I wrote in an external file.

var base = base || {};

base.requestAjax = function () {

    try{

        return new XMLHttpRequest();

    } catch (e) {

        try {

            return new ActiveXObject("Msxml2.XMLHTTP");

        } catch (e) {

            try {

                return new ActiveXObject("Microsoft.XMLHTTP");

            } catch (e) {

                alert("Something is wrong with your browser! Please ensure that you have javascript functionality enabled");
                return false;
            }
        }
      }
}

base.onReadyStateChange = function(ajaxRequest, formName, formArray, method, controller) {

    var methodVerified = verifyMethod(method);

    if (!methodVerified) {
        throw new Exception("Error: please make sure the method passed matches that of \'GET\' or \'POST\'.");
    } 

    for (input in formArray) {
        document.formName.input.value = ajaxRequest.responseText;
    }

    ajaxRequest.open(method, controller, true);
    file.send(null);
}


base.writeDropDownList = function(file, method, path) {

    var file = upload.requestAjax();

    file.open(method, path, true);

    if (file.readyState != 4) {
        throw new Exception("Error: text file ready state not equal to 4!");
    }

    if (file.status != 200) {
        throw new Exception("Error: text file status not equal to 200!");
    }

    var lines = file.responseText.split("\n");

    document.writeln("<select>");

        for(line in lines) {
        document.writeln("<option>" + line + "</option>");
    }

    document.writeln("</select>");

    file.send(null);    
}

base.verifyMethod = function(method) {

    var methodLower = method.toString().toLowerCase();

    switch(methodLower) {
        case "get":
        case "post":
            return true;

        default:
            return false;
    }
}

The html code which attempts to implement it

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="../includes/css/adsmanager.css" />
        <script type="text/javascript" src="../includes/js/base.js">
        <!--
        function createCountriesList() {
            var file = base.requestAjax;
            var path = "../includes/_notes/countries.txt";
            base.writeDropDownList(file, "GET", path);
        }
        //-->
        </script>
    </head>
    <body>

        <form name='adsManager'>
            <button type="text" value="test" onclick="createCountriesList()" />
        </form>

    </body>
</html>

I plan to use the functions for other things, so I figured I’d create a namespace. I found this as a reference and based most of my model off of it.

Thanks to all who can help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:44:27+00:00Added an answer on May 26, 2026 at 10:44 pm

    What is your point of failure? Is your Javascript sending the Ajax request and receiving the response?

    Is lines getting data in this line of your code?

     var lines = file.responseText.split("\n");
    

    If you are getting this far, iterate through lines and add options like this:

    var select = document.getElementById('id');
    select.options.add(new Option(lines[i]));
    

    In your writeDropDownList method, I made a few changes:
    added a method that will be called when your Ajax call has completed. In that method, you should check the response string and add the options to your select box

    base.writeDropDownList = function(file, method, path) {
    
        var file = upload.requestAjax();    
        file.open(method, path, true);    
        file.onreadystatechange = requestComplete;
        file.send(null);    
    }
      requestComplete()
      {
        if (file.readyState == 4) 
        {
           if(file.readyState == 200)
           {
               var lines = file.responseText.split("\n");
               //foreach loop to populate select
           }
       }                            
     }
    

    In your code, you are checking and using files.responseText before you have even sent the Ajax request at files.send(null)

    EDIT:

    Some more comments regarding your code:

    • In the createCountriesList function, you create file and assign
      it a value by calling requestAjax. You then pass it to
      writeDropDownList function, where you assign it a value again by
      calling requestAjax. You see that this is redundant? There is no
      need to create file in createCountriesList and pass it as an
      argument. Create it just once in writeDropDownList.

    • in writeDropDownList you call upload.requestAjax(). What is
      upload. I don’t see you initializing upload anywhere. Do you mean
      to call base.requestAjax()?

    • you have a function base.OnReadyStateChange but at no point are you
      telling your AJAX request to call that function when state changes. See the code I posted above. The function I added called
      requestComplete does that, and I tell the AJAX request to call it using file.onreadystatechange = requestComplete;

    • You set method to GET, yet you are not passing any GET values in your URL

    • in file.open(method, path, true);, path is supposed to be the URL of the script the AJAX request will call. You have set path to ../includes/_notes/countries.txt. An AJAX request cannot call a .txt file since they do not execute.

    I just had a look at the source of your code, and it is all sorts of broken. Please do not use it.

    What is countries.txt ? Are you attempting to populate a dropdown with a list of all countries, or some countries depending on user’s input?

    If the former, there is no need for Javascript / AJAX. You need to add PHP code in your html to populate the select box.

    If the latter, your AJAX request should be sending the user input as a GET variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Is this possible? Or would I miss something? (Fixtures,..?) Because: When I use autotest
I would like to use a clock like this one: W3 schools Javascript Clock
I am bootstrapping myself through my very first ASP MVC project, and could use
Back in the old days, Help was not trivial but possible: generate some funky
I could do with some help on my REST API. I'm writing a Node.js
does anyone know if possible or how to submit a form, use get to
Can anybody please explain how this could possibly happen? I am completely aware of
What could possibly cause this weird python behaviour? Python 2.6.2 (r262:71600, May 31 2009,
It this possible? How? (Maybe silly question, but I couldn't find answer :( )

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.