11-25-2008, 09:13 AM
|
#2 (permalink)
|
|
The Wanderer
Join Date: Mar 2008
Posts: 18
Thanks: 0
|
It's easy with jquery! I'll make an example for you:
some place in your form
HTML Code:
<select name="authors" id="authors" >
<option value="1">French</option>
<option value="2">American</option>
</select>
<select name="publisher" id="publisher" ></select>
JS to do all the ajax magic(I use jquery so you will need that to try my example too).
HTML Code:
$(document).ready(function(){
$("#authors").change(function(){
id = $("#authors").val();
$("#publisher").load("ajax.publisher.php?id="+id);
});
});
And the "ajax.publisher.php"
PHP Code:
<?php
session_start();
error_reporting(E_ALL);
include('config.php');
include('functions.php');
if(isset($_GET['id']) and ctype_digit($_GET['id']))
{
$sql = "SELECT * FROM publishers WHERE author_id = {$_GET['id']}";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result))
{
echo '<option value="'.$row['id'].'">'.$row['publisher'].'</option>';
}
}
?>
|
|
|
|