Jump to content

Sending Multiple Data Option Arrays Back To Jquery


Xtremer360

Recommended Posts

You've probably seen this many times with two dynamic linking select boxes that deals in form or another deal with countries and then cities for the second one or something similar well I have another question about that. I've looked at a few others and well their coding is so different then mine that I don't want to use code for my own project that I don't understand in case I need to reuse it for some other reason down the road.

 

The user selects a country and with the users selection it passes the countryid as a variable through jquery's ajax fuction as a post parameter to a php process page in which it goes to a table and matches the country id with the db field called country_id in the arenas table. With all the records that matches that countryid it selects the arena name and city that the arena is in and displays it as an option tag now I'm trying to figure out with muliple entries how can I pass the results back to the form page and insert it into the arenas dropdown box.

 

Following is my coding separated out for you. I only included the necessary parts. All help would be greatly appreciated.

 

form page

 

$('#countryid').change(function() {
      var countryid = $("select#countryid").val();
      var dataString = 'countryid='+ countryid;
      $.ajax({
        type: "POST",
        url: "processes/booking.php",
        data: dataString,
        success: function() {
            
        }
        });  
    });
<div class="field required">
    			<label for="countryid">Country</label>
                <select class="dropdown" name="countryid" id="countryid" title="Country">
                   <option value="0">- Select -</option> 
                    <?php
                    $query = 'SELECT id, countryname FROM countries';
                    $result = mysqli_query ( $dbc, $query ); // Run The Query
                    while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) 
                    {
                        print "<option value=\"".$row['id']."\">".$row['countryname']."</option>\r";
                    }
                    ?>
                </select>
    			<span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span>
    		</div>
            <div class="field required">
    			<label for="arena">Arenas</label>
                <select class="dropdown" name="arenas" id="arenas" title="Arenas">
                </select>
    			<span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span>
    		</div>

 

 

php process page

 

$countryid = (int)$_GET['countryid'];
$query = "SELECT * FROM `arenas` WHERE `country_id` = '$countryid'";
$result = mysqli_query ($dbc, $query);
while ($row = mysqli_fetch_array($dbc, $result))
{    
    echo '<option value="'.$row['arena'].'">'.$row['arena'].' - '.$row['city'].'</option>\n';
} 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.