我有兩個選擇選項,但我發現它們之間的JavaScript併發症很少。 這裏是我的javascript代碼:在javascript中的兩個選擇選項
function displayVals() {
var singleValues = $("select option:selected").text(); //to stay slected
$("#hiddenselect").val(singleValues); //hidden field of second select option
$("samp").html("" + singleValues); // this to insert text between samp tags
$("select > option:first").prop("disabled", "disabled") // this to disable first option
}
$(document).ready(function(){
$("select").change(function() {
displayVals();
});
displayVals();
$("select#menucompare").change(function() {
$("#aform").submit(); // second select options to submit
});
$("select#infmenu").change(function() {
$("#infform").submit(); // first select options to submit
});
});
現在我想到的是: - 只有第一個選擇的選項(第一個選項被禁用),還需要第二次選擇選項也(第一個選項被禁用)
這裏是我的html代碼 我的第一選擇選項:
<form action="" id="infform" method="post">
<select id="infmenu" name ="infmenu" size="1" class="select" onchange="submitinfform()" >
<option value="0" >Please Select your country</option>
<option value="<?php echo $row9['id'] ;?>" <?php if ($_SESSION['infmenu'] == $row9['id']) { echo " selected='selected'"; } ?> ><?php echo $row9['name'] ;?></option><?php } ?>
</select>
<input type="hidden" name="hiddenselect" value="<?php echo $infmenu; ?>" />
</form>
這第二個選擇選項
<form id="aform" method="post">
<select id="menucompare" name ="menucompare" size="1" class="select" onchange="submitaform()">
<option value="0">Select one</option>
<option value="west" <?php if ($menucompare == "west") { echo " selected='selected'"; } ?> >West</option>
<option value="est" <?php if ($menucompare == "est") { echo " selected='selected'"; } ?> >Est</option>
</select>
<input type="hidden" name="hiddenselect" value="<?php echo $menucompare ; ?>" />
</form>
我對這個多天花費沒有運氣 感謝您的時間
對不起,但我真的不明白你在這裏問什麼。你需要在語法上清理一下這個問題。 – Josh
編輯我的quesstion,但我不知道它現在清楚了,對不起我的英文不太好 –
沒問題,我不是想要變得卑鄙,只是努力瞭解你需要什麼幫助:) – Josh