How to use the Value of a Selected Value from a DropDownList populated with AJAX/PHP

Posted by mouthpiec on Stack Overflow See other posts from Stack Overflow or by mouthpiec
Published on 2010-04-10T14:01:15Z Indexed on 2010/04/10 14:03 UTC
Read the original article Hit count: 288

Filed under:
|
|

Hi,

I have form with two dropdownlists (lets say A and B). When I select a value from A, B is being populated accordingly using AJAX

In the same page I have a button, that when pressed, posts the values of the selected items of the dropdownlists to another PHP page. The problem I am having is that the selected value of B is returned as Blank/Empty.

Is there a way to store the selected value of a dropdownlist populated using AJAX?

Code below:

(Main FORM)

<form name="NewBar" method="post" onsubmit="return validateFormOnSubmit(this)" action="AssignContactDetailToBar_f.php"> 
           <tr>
                <td width="150"><b>Bar:</b></td>
                <td>                
                    <select name = "bar" onChange="getContact('AssignContactDetailToBar_f_getContacts.php?bar='+this.value)" size = 1 style = "width:190px">
                    <option value = "">---Select---</option>
                    <?php
                    while ($data = mysql_fetch_array($r_getBarsDetails))
                    {
                        echo "<option value=\"".$data['bar_id']."\">".$data['bar_name']." (".$data['town_name'].")</option>";
                    }
                    ?>
                </td>
            </tr>
            <tr>
                <td width="150"><b>Contact Person:</b></td>
                <td>                
                    <div id="persondiv"><select name = "person" size = 1 style = "width:190px">
                    <option value = "">--Select Bar--</option>
                </td>
            </tr>               
            <tr>
                <td>
                    <input name="security" type="text" size="15">
                </td>
                <td>
                    <input type="submit" name="Submit" value="Submit">
                </td>
            </tr>
        </form>

FORM to populate the 2nd Dropdownlist

<select name="person" size = 1 style = "width:190px">
<option value = "">--Select Person--</option>   
<?php 
while($data=mysql_fetch_array($result)) 
{ 
    echo "<option value=\"".$data['person_id']."\">".$data['person_name']." ".$data['person_surname']." (".$data['town_name'].")</option>";     
} ?>

if you would like to see the complete code download from here

© Stack Overflow or respective owner

Related posts about php

Related posts about AJAX