Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Okay, so I have 2 select boxes on my page, the first with the name "select" with the following options hard-coded:

<select name="select" id="Testid">
        <option value="Misc">Misc...</option>
        <option value="Stunt">Stunt</option>
        <option value="deathmatches">Deathmatches</option>
        <option value="Car"> Car </option>
        <option value="Races">Races </option>
    </select>

The second select box however (named "deleteTp") I want to populate with a mysql table depending on the selection of the first select box. Each option value has a specific table in my database with the same name as the value.

I know how to populate the second select box with the database table, however I'm not sure how to do this dynamically depending on the users choice.

Please note I only know basic javascript.

And if you're wondering why I am trying to do this, it's because the second selectbox will be posted to an external page to delete the rows from the populated table.

Thank you for your time.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
278 views
Welcome To Ask or Share your Answers For Others

1 Answer

$.ajax({
  type: 'post',
  url: "ajax.php."
  data: { id:'your id here' } //your id is your select box selected id.
}).done(function() { 

});

on php side :

$id = $_REQUEST['id']; 
$json = array();
$sql = mysql_query("select * from yourdb where id = $id");
while ($row = mysql_fetch_assoc($sql)) {
    $json[] = $row;
}
echo json_encode($json);

ajax ref : http://api.jquery.com/jQuery.ajax/

json ref: http://en.wikipedia.org/wiki/JSON


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...