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

  • SEARCH
  • Home
  • 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 6010623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:08:34+00:00 2026-05-23T02:08:34+00:00

When I load the page and change the option in the select menu, in

  • 0

When I load the page and change the option in the select menu, in debugging consoles I get an error saying that descrip() is not a function

<script type="text/javascript">
function descrip(){ 
    var aid = new XMLHttpRequest("GET",document.ads.subject.value,false);  
    var file = "includes/ads/"+aid+".txt";
    document.ads.descrip.write(file);
    return aid;
}
</script>

<form name="ads" method="post" action="scripts/del_advert_script.php">
<label>Advertisements by subject:</label><select name="subject" id="sub" onChange="descrip()">
        //PHP Block that works
    </select>
    <textarea id="descrip" name="description" cols="100" rows="3" readonly="readonly">

    </textarea>
    <br />
    <input type="submit" value="Submit" />
</form>
  • 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-23T02:08:34+00:00Added an answer on May 23, 2026 at 2:08 am

    There are four issues I see here: your XMLHttpRequest, your method of writing text to a <textarea>, your method of getting the currently selected value of a <select>, and your function shares the same name as an ID (a problem only in IE).

    AJAX doesn’t quite work the way you have it above, as unfortunate as that is. Instead, you have to jump through some hoops in order to get a request running and get its responseText back. Here is some example code:

    var xhr = XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
    xhr.onreadystatechange = function () {
        // When the server has returned a response, and it is good, we're ready
        if (xhr.readyState === 4 && xhr.status === 200) {
            // do something with xhr.responseText
        }
    };
    // Three arguments: type of request, url, and should the request be async
    xhr.open("GET", "url here", true);
    xhr.send(null);
    

    That is a very light example, but it does demonstrate the generic concept. For more on AJAX in general, see the MDC’S excellent tutorial on beginning AJAX.

    Next, there is no write function for a <textarea> in the DOM. In order to change what is in the textarea, you need to use its value property:

    your_textarea.value = "something here";
    

    Or if you want to append new text to the textarea:

    your_textarea.value += "something here";
    

    This will insert text properly.

    Thirdly, your method of ascertaining the current selected <option>‘s value in a <select> also does not work (unfortunately). In order to grab the value of the currently selected option, you have to use the selectedIndex property of a <select> as well as its options property:

    your_select.options[your_select.selectedIndex].value;
    

    This will properly return the value of the currently selected option.

    Finally, and this is only an issue in IE, your function shares the same name as an ID. In IE, any IDs get defined globally as DOM elements, so this is an issue. So, simply changing your function’s name to something else should alleviate that issue.

    All-in-all, here is the code I believe works (though untested):

    <script type='text/javascript'>
    function select_change() {
        var xhr = XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
        xhr.onreadystatechange = function () {
            // When the server has returned a response, and it is good, we're ready
            if (xhr.readyState === 4 && xhr.status === 200) {
                var file = "includes/ads/" + xhr.responseText + ".txt.";
                document.ads.descrip.value += file;
            }
        };
        // Three arguments: type of request, url, and should the request be async
        xhr.open("GET", 
                document.ads.subject.options[document.ads.subject.selectedIndex].value, 
                true);
        xhr.send(null);
    }
    </script>
    
    <form name="ads" method="post" action="scripts/del_advert_script.php">
    <label>Advertisements by subject:</label><select name="subject" id="sub" onchange="select_change()">
            //PHP Block that works
        </select>
        <textarea id="descrip" name="description" cols="100" rows="3" readonly="readonly">
    
        </textarea>
        <br />
        <input type="submit" value="Submit" />
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following markup on page load: <select name=sel_billing_address></select> After page load that
I have an ASP.net mvc page that executes a jquery script on load. The
I have a javaScript function that updates a select inputs options. The function works
I am trying to get the following code to fire once on page load/refresh
I'm trying to load page and then remove some elements in it. While doing
I've previously used jquery-ui tabs extension to load page fragments via ajax , and
Upon page load I want to move the cursor to a particular field. No
Is Page.Load the earliest point in the Page.Load life cycle to add Response.AppendHeader?
If I load a page in an iframe, run doc.querySelect to retrieve a node
I have a php function which inserts a searchbar into each page on a

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.