Mam formularz i chcę jeżeli ktoś wybierze woj. np Dolnośląskie aby to zostało zapamiętane.
Przykład działania poniższego kodu tutaj: klik
Index.php
<?php include('../conf/db.php'); $db = mysql_connect ($db_host, $db_user, $db_pass) or die ("<br><br><center><br><br><b>Wystapil problem z serwerem $dbtype, Przepraszamy za problemy.<br><br>Wracamy wkrótce.</center></b>"); include('func.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=utf-8" /> <title>Zobacz</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#wait_1').hide(); $('#drop_1').change(function(){ $('#wait_1').show(); $('#result_1').hide(); $.post("func.php", { func: "drop_1", drop_var: $('#drop_1').val() }, function(response){ $('#result_1').fadeOut(); setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400); }); return false; }); }); function finishAjax(id, response) { $('#wait_1').hide(); $('#'+id).html(unescape(response)); $('#'+id).fadeIn(); } function finishAjax_tier_three(id, response) { $('#wait_2').hide(); $('#'+id).html(unescape(response)); $('#'+id).fadeIn(); } </script> </head> <body> <p> <form action="" method="post"> <select name="drop_1" id="drop_1"> <option value="" selected="selected" disabled="disabled">Wybierz województwo</option> <?php getProvinceOne(); ?> </select> <span id="wait_1" style="display: none;"> <img alt="Please Wait" src="ajax-loader.gif"/> </span> <span id="result_1" style="display: none;"></span> <span id="wait_2" style="display: none;"> <img alt="Please Wait" src="ajax-loader.gif"/> </span> <span id="result_2" style="display: none;"></span> </form> </p> <p> $drop = $_POST['drop_1']; $drop_2 = $_POST['drop_2']; $drop_3 = $_POST['drop_3']; } ?> </body> </html>
oraz drugi plik func.php
<?php include('../conf/db.php'); $db = mysql_connect ($db_host, $db_user, $db_pass) or die ("<br><br><center><br><br><b>Wystapil problem z serwerem $dbtype, Przepraszamy za problemy.<br><br>Wracamy wkrótce.</center></b>"); function getProvinceOne() { { } } drop_1($_POST['drop_var']); } function drop_1($drop_var) { echo '<select name="drop_2" id="drop_2"> <option value=" " disabled="disabled" selected="selected">Wybierz miasto</option>'; { } echo "<script type=\"text/javascript\"> $('#wait_2').hide(); $('#drop_2').change(function(){ $('#wait_2').show(); $('#result_2').hide(); $.post(\"func.php\", { func: \"drop_2\", drop_var: $('#drop_2').val() }, function(response){ $('#result_2').fadeOut(); setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400); }); return false; }); </script>"; } drop_2($_POST['drop_var']); } function drop_2($drop_var) { echo '<select name="drop_3" id="drop_3"> <option value=" " disabled="disabled" selected="selected">Wybierz kod</option>'; { } } ?>