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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:39:35+00:00 2026-06-04T17:39:35+00:00

I have a simple HTML form which starts with a select menu where the

  • 0

I have a simple HTML form which starts with a select menu where the user can select from a list of Projects. I’ve created a simple JSFiddle with the HTML form here:

http://jsfiddle.net/AZ4PM/

What I would like to happen is that when the user selects from the list it triggers a php script to be performed which takes the value from the ProjectNumber they have selected and passes this as a parameter, e.g. if I select Project A the URL would be:

getProjectPhases.php?projectNumber=10000

This php script will then return a new table cell which I would then like to appear as the 2nd cell in the form. It contains a new select menu with the values changing depending on the selection in the first select menu. This php page is working well manually, but I’m at the point now where I need to have it triggered when the user makes a selection from the Project Number menu.

I’m new to AJAX and would like to start with a simple example one step at a time whilst I learn. I’m happy to use jQuery if that makes things easier.

Appreciate any pointers to what the basic elements I need to include (assuming at least one js file etc).

  • 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-04T17:39:36+00:00Added an answer on June 4, 2026 at 5:39 pm

    I have something very similar that I use:

    <select name="selectProject" id="selectID" onChange="showUser(this.options[selectedIndex].value)">
    
        <?php
            // Loop through and list each project
            foreach ($var as $row) {
                echo '<option value="'.$row['projectNumber'].'">'.$row['projectName'].'</option>';
            }
        ?>
    
    </select>
    
    <label>Project Name</label>
    <input id="projectName" type="text" class="span3" name="projectName">   
    

    The above just calls the showUser function with the parameter that is the projectNumber

    Then below that I have:

    <SCRIPT TYPE="text/javascript">
    
        // Function to fill in form fields
        function showUser(str)
        {
        if (str=="")
          {
          document.getElementById("").innerHTML="";
          return;
          }
        if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
          }
        else
          {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        xmlhttp.onreadystatechange=function()
          {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                var obj = eval('(' + this.responseText + ')');
    
    
                document.getElementById("projectName").value=obj.projectname;
            }
          }
        xmlhttp.open("GET","http://url.com/ajax/"+str,true);
        xmlhttp.send();
        }
    </SCRIPT>
    

    This script will call the url url.com/ajax/whateverIdIsSelected

    From that page, you want to do whatever you have to do with your query.

    As for what to return, I have this set up to use json, which I why I have the line

     var obj = eval('(' + this.responseText + ')');
    

    this.reponseText is what is returned from the ajax page. My return call looks like this

    $projectData = json_encode($project);
    
    echo $projectData;
    

    Where $project is an array containing your project’s attributes.

    I’m not very good with ajax or js, but I got this working the way I like it. Let me know if you have questions

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

Sidebar

Related Questions

I have a simple HTML form which consists of radio buttons where user has
I have a simple html form with select element. To define which option is
I have a simple MVC form with the following elements: <%= Html.TextBox(FechaInicio) %> Which
I have a simple html form. On php page. A simple list is placed
I have an HTML page with a simple form. When the user clicks submit,
I have a simple HTML form that posts to a PHP page, which will
I have a simple HTML Form that allows the user to enter some text
I have a form, which at the moment is a simple HTML based one,
I have a simple html form: <form action="/api/userattributes" method=get> <select name=action> <option>read_by_user</option> <option>set</option> <option>delete</option>
I have created a Django app. I have a registration page(simple HTML form) in

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.