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 7957827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:19:18+00:00 2026-06-04T04:19:18+00:00

i have an ajax script which is used to set the user location, the

  • 0

i have an ajax script which is used to set the user location, the form input is a

<select id="region" onchange="city('/ajax-city.php')" ...>
   <option>

<select ..\>
   <option...>

when one of the options in the first select list is changed (onchange) an ajax request is sent to the server and the response is proccessed and the second <select> is updated.

it’s the function used to update the <select>

var city = function(page)
{
    if(xhro){ // stands for Xml Http Request Object
      var fv = document.getElementById('region').value;
      var obj = document.getElementById('city-element');
      obj.innerHTML="<span style=\"display:block; width:200px; float:right; padding:0 10px 10px 0; font-family:Tahoma; font-size:12px;\"> please wait.. </span>";
      xhro.open("POST",page);
      xhro.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      xhro.onreadystatechange = function()
      {
        if(xhro.readyState==4 && xhro.status==200)
        {
            obj.innerHTML = "<select name=\"city\"  onchange=\"subcity('ajax-subcity.php')\" id=\"city\" >"+xhro.responseText+"</select>";
        }
      }
      xhro.send("city=" + fv);
}

as you can see my function adds onchange attribute in order to send another ajax request when the <select name="city"> onchange event is trigged, but when i click on the next option in the <select name="city">, in console in firebug i get this error

subcity is not a function

subcity("ajax-subcity.php");

and when i type the function in console firebug recognizes it, i think when an ajax request updates DOM elements the events are not handle like when the page normally loads.

but that is just a suggestion consider that the function city() is handled and updates <select name="city>" but in the next level(subcity()) no update happens

and creating the <option ..> s is done with php script.

it think the problem in not the subcity() function because it works in firebug BTW it’s good to be mentioned.

var subcity = function(page){
alert("problem solved");
if(xhro){
    var fv = document.getElementById('city').value;
    var obj = document.getElementById('subcity-element');
    obj.innerHTML="<span style=\"display:block; width:200px; float:right; padding:0 10px 10px 0; font-family:Tahoma; font-size:12px;\"> please wait</span>";
    xhro.open("POST",page);
    xhro.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhro.onreadystatechange = function(){
        if(xhro.readyState==4 && xhro.status==200){
            obj.innerHTML = "<select name=\"subcity\" id=\"subcity\" >"+xhro.responseText+"</select>";
        }
    }
    xhro.send("city=" + fv);
}
  • 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-06-04T04:19:19+00:00Added an answer on June 4, 2026 at 4:19 am

    i quote :

       if(xhro.readyState==4 && xhro.status==200){
                obj.innerHTML = "<select name=\"subsity\" id=\"subcity\" >"+xhro.responseText+"</select>";
            }
    

    Change the subcity id you use in your select ,please use “sub-city” instead of “subcity” or it will overwrite your subcity function !!!

    ids are used by javascript , that’s why they must be unique. , it is not just for CSS.

    EDIT :

    do the same for city and city function

    PS : your code is a mess , seriously ! fix it.

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

Sidebar

Related Questions

I have a form for which I used AJAX for submitting the form and
I have a jquery-ajax function that sends data to a php script and the
I have java script code to set some of the properties of ajax controls.
I have a php script that gets called via an ajax call. Values are
I have this jQuery script var dataString = class_id=+class_id; $.ajax({ type: POST, url: page.php,
I have an application that posts data to a php script through jquery's ajax
I have an ajax call which will return a set<E> . I need to
I have an ajax code which passes data to php and then retrieves data
I have a form which I call via AJAX (for use on a CMS)
Here is the form to have ajax check out user existence. <!DOCTYPE html> <html>

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.