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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:10:19+00:00 2026-06-12T04:10:19+00:00

I am trying to create a smart form which will automatically limit the options

  • 0

I am trying to create a smart form which will automatically limit the options available of a second drop down box.

Background:
I am creating a ticketing system and I would like for the user to select a site from the “Site Selection” drop down and then the “User Selection” drop down will only contain users linked to the site selected on the first drop down, all information populated from MySQL.

Future:
I would then like to list all the services associated to that user with tick boxes under “Select Affected Services”

My js is pretty poor. So far I have been able to find some code by searching here that has allowed me to write the User’s Computer ID into a text field. But I cannot figure out how to capture the output and query for the Computer Name (different table) and display that as a tick box option or to use the same method to limit the next lot of selection boxes. All code listed below I have not cleansed yet, alpha phase.

I realise that I could do this in steps using PHP only, but I am trying to pretty up my coding here and there.

Displaying Drop Downs:

    <h3>Assign Site</h3> 

    <select id="site_add" name="site_add" style="width:217px; height:20px !important;">
        <option value="-1"></option>';

  $o = "SELECT * FROM company_sites WHERE company_id = " . $company_id . " ORDER BY sitename";
$rs = mysql_query($o);
$nr = mysql_num_rows($rs);
for ($i=0; $i<$nr; $i++) {
$r = mysql_fetch_array($rs);
        echo '<option value="' . $r['id'] . '">' . $r['sitename'] . '</option>';
    }

    <h3>Assign User</h3> 
    <select id="comp_add" name="comp_add_1" style="width:217px; height:20px !important;">
        <option value=""></option>';

  $o = "SELECT * FROM company_staff WHERE company_id = " . $company_id . " ORDER BY id DESC";
$rs = mysql_query($o);
$nr = mysql_num_rows($rs);
for ($i=0; $i<$nr; $i++) {
$r = mysql_fetch_array($rs);

    $user_computer_id = $r['computer_id'];

        echo '<option value="' . $r['id'] . '">' . $r['firstname'] . ' ' . $r['lastname'] . '</option>';
    }

Current JS to output selected user’s computer ID into text field:

<script type="text/javascript"> 
window.onload=function() { attachBehaviors(); }; 
// 
function attachBehaviors() { 
 document.getElementById(\'person\').onchange=function() { 
 loadUser(this.options[this.selectedIndex].value); // <-- check this, may be incorrect 
 } 
} 
function loadUser(optionvalue) { 
 // Always set a default 
 if (optionvalue==\'\') {  
 return; 
 }
 opts = optionvalue.split(\':\'); 
 var name = opts[0]; 
 var email = opts[1]; 
 document.getElementById(\'computer_id\').value=name; 
} 

</script> 

<select name="person" id="person"> 
    <option value=""></option>';


$result=mysql_query("SELECT * FROM company_staff"); 
while($row=mysql_fetch_array($result)) { 

$submit_firstname = $row['firstname']; 
$submit_lastname = $row['lastname']; 
$submit_staff_id = $row['id']; 
$submit_computer_id = $row['computer_id']; 


 echo '<option value="' . $submit_staff_id . '">' . $submit_firstname . ' ' . $submit_lastname . '</option>\n'; 
} 
echo '
</select> 
<input type="text" id="computer_id" name="name" placeholder="name" /> 
';

Any recommendations on how to achieve this would be greatly appreciated!

Thanks in advance!

  • 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-12T04:10:20+00:00Added an answer on June 12, 2026 at 4:10 am

    You need AJAX, it’s a combination of PHP and JS. ( javascript request data from the server, php processes the request, returns data ).

    You would need to practice AJAX a bit to understand how to make this select box.

    This is process in theory:

    1. You output your first select box with PHP.
    2. Make an onchange event handler for it that would call a server for information.

      ..options..

    3. This updateNewDropDown function will take the value form a server response you selected and fetch the new data via PHP for the second select menu, and create the new select menu with the data AJAX response provided.

    AJAX TUTORIALS:

    http://api.jquery.com/jQuery.ajax/
    http://www.w3schools.com/ajax/default.asp

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

Sidebar

Related Questions

I am trying to create a simple web form which will give me a
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying to create an animation in which a circle will be containing
I'm trying to develop a simple program which will show a form with a
I'm trying to create a simple form which calculates the values in every input
I'm trying to create a form that will allow users to edit data. I
Trying to create a macro which can be used for print debug messages when
Trying to create a background-image slideshow and am getting this error... This is the
I'm trying to create a form whose layout is entirely data driven. Example data
I am trying do one of the following in the Create Event 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.