[英]Pass values based on different select option
我試圖根據用戶從下拉列表中選擇的選項獲取不同的值。 例如。 當用戶從下拉列表中選擇選項 1 => 將值 111 傳遞給 .$numbers 時
我怎么做? 我應該在 //some code 區域中包含哪些代碼?
switch($_POST['outlet']){
case 'a' :
//some code;
//get value 111 from here
break;
case 'b':
//some code;
//get value 222 from here
break;
case 'c':
//some code;
//get value 333 from here
break;
default:
//some code if the post doesn't match anything
}
你可以這樣做:
<select id="sc" name="outlet">
<option value="111">1</option>
<option value="222">2</option>
</select>
<select id="sh" name="outlet">
<option value="333">3</option>
<option value="444">4</option>
</select>
<select id="sw" name="outlet">
<option value="555">5</option>
<option value="666">6</option>
</select>
Then, just take the value of $_POST['outlet']
$numbers = null;
switch($_POST['outlet']){
case 'a' :
//some code;
//get value 111 from here
$numbers = 111;
break;
case 'b':
//some code;
//get value 222 from here
$numbers = 222;
break;
case 'c':
//some code;
//get value 333 from here
$numbers = 333;
break;
default:
//some code if the post doesn't match anything
break;
}
echo is_null($numbers) ? 'Numbers is null' : $numbers; // <- correct value
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.