私は開発に慣れていないので用語が間違っていたらすみませんが、複数のドロップダウンメニューがリンクされているので、前のメニューの結果が次のメニューが次に何を入力するかを決定します.
つまり、英国を選択すると、次のリストにロンドンが表示され、スペインを選択すると、次のリストにマドリッドが表示されます
ドロップダウン メニューが mysql によって取り込まれています。これは問題ありませんが、別のページを呼び出さずにそれらをリンクするにはどうすればよいですか
私が持っているHTMLの例を次に示します。
<div id="container">
<h3>Price List</h3>
<form method="post" action="" name="form1">
<?
include 'classes.php';
$query="SELECT * FROM Sex_Table";
$result=mysql_query($query);
?>
<div id="select-1">
<select class="calculate" name="sdf" onChange="getClothing(this.value)">
<option value="0">Please Select</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value=<?=$row['Price']?> sex_price="<?=$row['Price']?>"><?=$row['Sex_Name']?> (£<?=$row['Price']?>)</option>
<? } ?>
</select>
</div>
<?
$Sex=intval($_GET['Sex_var']);
include 'classes.php';
$query="SELECT * FROM Clothing_Table WHERE Sex_Table_ID='$Sex'";
$result=mysql_query($query);
?>
<div id="select-2">
<select class="calculate" name="sdf" onChange="">
<option value="0">Please Select</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value=<?=$row['Price']?> sex_price="<?=$row['Price']?>"><?=$row['Clothing_Name']?> (£<?=$row['Price']?>)</option>
<? } ?>
</select>
</div>
</form>
「getClothing(this.value)」の変更呼び出しで気付くでしょう。
そのjsは次のとおりです。
function getClothing(Sex_Table_ID) {
$.ajax({
type: "get",
url: "findClothing.php",
data: { Sex_var: Sex_Table_ID },
error: function(error) { alert('System error, please try again.'); },
success: function(data){ //data is the response from the called file
$("#select-2").html(data); //this changes the contents of the div to data that was returned
}
});
}
URL「findClothing.php」を呼び出さないようにする必要があります。これを行うと、価格が計算されなくなります。
この部分を実際に表示する必要はないと確信していますが、念のため、ここで私の価格を計算します。
$(function(){
$('.calculate').change(function() {
var total = 0;
$('.calculate').each(function() {
if($(this).val() != 0) {
total += parseFloat($(this).val());
}
});
$('#total').text('£' + total.toFixed(2));
});
});//]]>