我正在使用Magento和使用自定义选项。我有5个自定义选项,允许用户选择项目的条件。我希望下面的一些文本来显示当他们选择它时条件意味着什么。
很抱歉给你造成了困惑。我希望当选择适当的选项时,它能在屏幕上实时更新。这是我当前的代码,但它不显示文本。
<select name="options[1][]" id="select_1" class="multiselect required-entry product-custom-option" title="" onchange="opConfig.reloadPrice()">
<option value="1" price="0" >Perfect </option>
<option value="2" price="-35" >Excellent </option>
<option value="3" price="-105" >Good </option>
<option value="4" price="-140" >Poor </option>
<option value="5" price="-252" >Broken </option></select>
<?php if( $_POST['select_1']=='1' ){
echo "Perfect Condition Text";
}elseif( $_POST['select_1']=='2' ){
echo "Excellent Condition Text";
}elseif( $_POST['select_1']=='3' ){
echo "Good Condition Text";
}elseif( $_POST['select_1']=='4' ){
echo "Poor Condition Text";
}elseif( $_POST['select_1']=='5' ){
echo "Broken Condition Text";
} ?>
将<select>
名称更改为select_1
将解决您的问题:
<select name="select_1" id="select_1" class="multiselect required-entry product-custom-option" title="" onchange="opConfig.reloadPrice()">
如果由于某些原因不能更改名称,则将$_POST['select_1']
更改为$_POST['options'][1][0]
如果你想显示<select>
的值而不刷新页面,那么你可以使用javascript或jquery。下面是一个Javascript示例:
<script language="javascript">
function displayCondition() {
condition = new Array("", "Perfect", "Excellent", "Good", "Poor", "Broken");
var getsel = document.getElementById('select_1').value;
document.getElementById("divId").innerHTML = condition[getsel];
}
</script>
</head>
<body>
<form name="formName">
<select name="options[1][]" id="select_1" class="multiselect required-entry product-custom-option" title="" onchange="displayCondition()">
<option value="0">Select Condition</option>
<option value="1" price="0" >Perfect</option>
<option value="2" price="-35" >Excellent</option>
<option value="3" price="-105" >Good</option>
<option value="4" price="-140" >Poor</option>
<option value="5" price="-252" >Broken</option>
</select>
<div id="divId" name="divName" ></div>
</form>
</body>
</html>
该数组在PHP $_POST
中将无法通过select_1
索引使用但PHP $_POST
将有options
数组$_POST['options']
post数组名称基于表单元素的名称,而不是表单元素的id。把你的select元素的name属性改为"select_1",你就会得到你想要的了