ajax_start.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2"> <title>jQuery: dynamiczne pola select</title> <script type="text/javascript" src="http://ajax.googleapis.com/ ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $(".marka").change(function() { var id = $(this).val(); var dataString = 'id='+ id; $.ajax ({ type: "POST", url: "ajax_model.php", data: dataString, cache: false, success: function(html) { $(".model").html(html); } }); }); }); </script> </head><body> <div><h4>Link do wpisu: <a href="http://blog.tobiasz.org/2010/08/jquery-powiazane-pola-select/">kliknij tutaj</a></h4></div> <div align="center"> <?php include("cone.php"); echo '<select name="marka" class="marka" width="25">' .'<option selected="selected">--wybierz markę--</option>'; $data = $row['marka']; } echo '<select class="model" name="model">' .'<option selected="selected">--wybierz model--</option>' .'</select>'; ?> </div> </body></html>
ajax_model.php
<?php $mid = $_POST['id']; include("cone.php"); $model = $row['model']; } } ?>