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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:40:18+00:00 2026-06-06T18:40:18+00:00

i am trying to edit a select list every time the list before it

  • 0

i am trying to edit a select list every time the list before it is being changed.
what i am trying to do is change the list already existing into another list, called by a php function, that generates a list of the new information it has from the first list and an sql database.

it’s pretty hard to explain so here is my code:

the base of my code

//php & html
....

$cli = lastNameList();       //first list
$tli = firstNameList();   //second list

echo"

$cli
<div id='editHtml'>$tli</div>

";

....

functions (php)

//the functions

function lastNameList(){

$options="<select id='lastNames'>"; 

$sql="SELECT * FROM lastName";
$result=mysql_query($sql); 

$options.="<option value='blank'>-- last names --</option>" ;
while ($row=mysql_fetch_array($result)) { 

$name=$row["name"]; 

$options.="<option value='$name'>$name</option>"; 
} 

$options.= "</SELECT>";
return "$options";
}


function firstNameList(){

$options="<select id='firstNames' style='margin-right:40px;'>"; 

having a problem over here:

$sql="SELECT DISTINCT Name FROM firstName WHERE LastName ='lastNameSelectedGoesHere'";
//how do i get the value of the last name so i could make a query for it?

//using distinct to make sure there are no duplicates

$result=mysql_query($sql); 

$options.="<option value='blank'>-- first name --</option>" ;
while ($row=mysql_fetch_array($result)) { 

$name=$row["Name"]; 
$options.="<option value='$name'>$name</option>"; 
} 

 $options.= "</SELECT>";
return "$options";
}

js (inside a php file if it matters)

echo"  <script type='text/javascript'>
$('#lastNames').change(function() {

 document.getElementById('eTech').innerHTML="; 

 $ll = firstNameList();
 echo"$ll;

});";

so as you can see my js file is in a php file, it does work, what i tried to do there, is generate a new first name list to come and replace the old one but i failed… anyone has an answer or suggestion to what i should do?

  • 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-06T18:40:19+00:00Added an answer on June 6, 2026 at 6:40 pm

    THis isn’t complicated at all using ajax & jquery!

    A quick dirty way is to do this

    <div id="firstName"></div>
    <script type='text/javascript'>
    $('#lastNames').change(function() {
    $('#firstName').load('getfirstname.php?lastname=' + $(this).val());
    });
    </script>
    

    and for getfirstname.php page

    $lastName = mysql_real_escape_string($_GET['lastname']);
    $sql="SELECT DISTINCT Name FROM firstName WHERE LastName ='$lastName'";
    
    
    //using distinct to make sure there are no duplicates
    
    $result=mysql_query($sql); 
    $options="<select id='firstNames' style='margin-right:40px;'>";
    $options.="<option value='blank'>-- first name --</option>" ;
    while ($row=mysql_fetch_array($result)) { 
    
    $name=$row["Name"]; 
    $options.="<option value='$name'>$name</option>"; 
    } 
    
     $options.= "</SELECT>";
    echo $options;
    

    Here is a very simple page that shows how to execute php code using ajax and jquery.

    <?
    if(!isset($_GET['value'])):?>
    <script src="jquery-1.7.1.js"></script>
    <select id="select" >
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</options>
    </select>
    
    <div id="phpoutput"></div>
    
    <script>
        $('#select').change(function() {
        $('#phpoutput').load('?value=' + $(this).val());
        });
    
    </script>
    <?else:
        $val = $_GET['value'];
        echo "$val sent to server. $val*3 = " . $val *3;
     ?>
    <?endif;?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement an Edit ViewModel for my Linq2SQL entity called Product.
I am trying to change the value of only the very next select box
i am trying to create a select element with JS or even edit an
I'm trying to use a select list to actively filter the results I get
I am trying to make a report use a drop-down list (select list) for
I am trying to submit all the items in a select list to an
I'm trying to create a dropdown list with 'select' html tag , however ,
I'm trying to add a multiple select list to my backend component, but I
EDIT: changed the title to fit the code below. I'm trying to retrieve a
I'm trying to use LINQ expressions to dynamically select columns from an IEnumerable into

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.