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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:15:10+00:00 2026-06-16T20:15:10+00:00

***EDIT @alditis TY, tried your suggestion but the Javascript doesn’t work after it. This

  • 0

***EDIT

@alditis TY, tried your suggestion but the Javascript doesn’t work after it. This one doesn’t need to be that secure as there’s no sensitive data involved and I’m kinda learning it as I go along. Also I will be using these queries a lot more down the track so I would prefer having the entire array in there.

@Barmar yes it does, the second last snippet shows how Google Chrome sees the output using it’s debugger. This is why it’s so weird.

@FreudianSlip I was trying something and never put it back.

@saeed arab sheybani I don’t really understand? The code works and the lists populate just fine the problem is $_REQUEST['pos_no'] doesn’t exist it seems. It should work on submit as per the output code. Perhaps I am not getting what you are saying, would you have an example you can link me to?


I’m trying to get a PHP/Javascript dynamically populated combo box working through mysql queries and to the most part it works fine, that is until I hit the submit button. The scripts do exactly what I want up to this point.

From what I can see the replacement code is left out of the $_POST array. I assume this is happening because once the form loads it lists what fields to expect or creates the $_post array on the spot, therefore by inserting some new code it perhaps ignores it? Just a guess but seems logical, if so, how would one work around this? This has plagued me for a month or so now.

Javascript:

<script type="text/javascript">
    $(document).ready(subpos_selectbox_change);
    function subpos_selectbox_change(){
        $('#subpos').change(update_position_number);
    }
    function update_position_number(){
        var subpos=$('#subpos').attr('value');
        $.get('get_list.php?subpos='+subpos, show_posnumbers);
    }
    function show_posnumbers(ss){
        $('#position_number').html(ss);
    }
</script>

get_list.php

switch($_REQUEST['subpos']){

    case 'AO2';
        $teamQuery = "SELECT * FROM establishment_positions WHERE position_filled='0' AND active='1' AND position_acrynom='AO2'";
        break;

    case 'AO3';
        $teamQuery = "SELECT * FROM establishment_positions WHERE position_filled='0' AND active='1' AND position_acrynom='AO3'";
        break;

    case 'AO4';
        $teamQuery = "SELECT * FROM establishment_positions WHERE position_filled='0' AND active='1' AND position_acrynom='AO4'";
        break;

    case 'AO5';
        $teamQuery = "SELECT * FROM establishment_positions WHERE position_filled='0' AND active='1' AND position_acrynom='AO5'";
        break;

    case 'AO6';
        $teamQuery = "SELECT * FROM establishment_positions WHERE position_filled='0' AND active='1' AND position_acrynom='AO6'";
        break;

    case 'AO7';
        $teamQuery = "SELECT * FROM establishment_positions WHERE position_filled='0' AND active='1' AND position_acrynom='AO7'";
        break;

    case 'AO8';
        $teamQuery = "SELECT * FROM establishment_positions WHERE position_filled='0' AND active='1' AND position_acrynom='AO8'";
        break;

    case 'SO1';
        $teamQuery = "SELECT * FROM establishment_positions WHERE position_filled='0' AND active='1' AND position_acrynom='SO1'";
        break;

}

echo '<select name="pos_number" id="pos_number">';
$ss = null;
$result = mysql_query($teamQuery);
while($row = mysql_fetch_array($result))
{
    $ss.= '<option value=' . $row['position_id'] . '>' . $row['position_number'] . '</option>';

}
echo $ss;
echo '</select>';

..and here id the html code before the Javascript goes to work:

<div class="newusr">
    <table>
        <form id="newusr" action="includes/insertuser.php" method="post">
            <tr><td>First Name: </td><td><input type="text" name="firstname"></td></tr>
            <tr><td>Middle Name: </td><td><input type="text" name="middlename"></td></tr>
            <tr><td>Last Name: </td><td><input type="text" name="lastname"></td></tr>
            <tr><td>Username: </td><td><input type="text" name="usr"></td></tr>
            <tr><td>sex:</td><td><select name="sex"><option value="1">Male</option><option value="0">Female</option></select></td></tr>
            <tr><td>Position: </td><td><select name="subpos" id="subpos"><?php echo $subpos; ?></select><td></tr>
            <tr><td>Position No: </td><td id="position_number"><select name="pos_number"><option value="">choose a Position first</option></select></td></tr>
            <tr><td>Contractor: </td><td><input type="checkbox" name="contractor" value="1"></td></tr>
            <tr><td>Start date: </td><td><input type="date" name="empStrtDte"></td></tr>
            <tr><td>Active: </td><td><input type="checkbox" name="active" value="1"></td></tr>
            <tr><td><?php echo '<input type="submit"><input type="reset" value="Reset"></td></tr>'; ?>
        </form>
    </table>
</div>

HTML code after I change a value in subpos (from Chrome):

<select name="subpos" id="subpos">
    <option value="AO2">AO2</option>
    <option value="AO3">AO3</option>
    <option value="AO4">AO4</option>
    ...
</select></td>
<select name="pos_number" id="pos_number">
     <option value="2">805620121</option>
     <option value="10">805678998</option>
</select>

All looks good, does exactly what I want at this point. Then I print the array and boom, missing the pos_number value and I have no idea why.

Array
(
    [firstname] =&gt; test
    [middlename] =&gt; test
    [lastname] =&gt; test
    [usr] =&gt; 
    [sex] =&gt; 1
    [subpos] =&gt; AO3
    [empStrtDte] =&gt; 2012-02-19
)
  • 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-16T20:15:12+00:00Added an answer on June 16, 2026 at 8:15 pm

    Problem was Javascript wasn’t binding the results to the DOM. Used some JQuery instead. Huzzaah.

    Thanks to all that contributed.

    JavaScript:

    <script type="text/javascript">
                $(document).on('change', "#subpos", function(){
                    var subpos=$('#subpos').attr('value');
                    $.get('get_list_test.php?subpos='+subpos, function(ss){
                        $('#pos_number').html(ss);
                    });
                });
    </script>
    

    HTML:

    <tr><td>Position No: </td><td><select name="pos_number" id="pos_number"><option value="">choose a Position first</option></select></td></tr>
    

    PHP:

    $teamQuery = "SELECT * FROM establishment_positions WHERE position_filled='0' AND active='1' AND position_acrynom='".mysql_real_escape_string($_REQUEST['subpos'])."'";
    
    $ss = null;
    $result = mysql_query($teamQuery);
    while($row = mysql_fetch_array($result))
    {
        $ss.= '<option value=' . $row['position_id'] . '>' . $row['position_number'] . '</option>';
    
    }
    echo $ss;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT : It turned out that this can only be done through an external
Edit 08/01/2014 As of this edit time I realised that the subject property db.UserProperty()
EDIT: IS there any pre-built libraries to do this for me, that either uses
--EDIT-- I believe this is a valid question that may have multiple answers (as
EDIT: This question was originally about checkboxes, but I am getting the same behavior
edit : I based this question on a false assumption - that the generic
-- EDIT: I just realized that the right answer to this is maybe a
Edit: This question has been moved to Getting an error from Xcode that is
EDIT: For those struggling with this, checkout this link . Follow it carefully, but
Edit I realized my error shortly after posting this. The append should be 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.