Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1025208
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionI have a select option like this
<select name="select1">
<option value="value1">hots</option>
<option value="value2">popular</option>
<option value="value3" >new</option>
<option value="value4">old</option>
</select>
when a user select one option in the next loading the selected option again is the first one (value1), i managed to find an official solution, i used a switch case, like this:
$panir=$_POST['select1'];
switch ($panir) {
case 'value1':
?>
<select name="select1">
<option value="value1" selected>hot</option>
<option value="value2">popular</option>
<option value="value3" >new</option>
<option value="value4">old</option>
</select>
<?php
break;
case 'value2':
?>
<select name="select1">
<option value="value1">hot</option>
<option value="value2" selected>popular</option>
<option value="value3">new</option>
<option value="value4">old</option>
</select>
<?php
break;}
it works great, but has a big problem, i have another select option with lots of options and i can't add case as number as them, isn't there any solution that options would be selected by a condition? thanks a lot.
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionI have a select option like this
<select name="select1">
<option value="value1">hots</option>
<option value="value2">popular</option>
<option value="value3" >new</option>
<option value="value4">old</option>
</select>
when a user select one option in the next loading the selected option again is the first one (value1), i managed to find an official solution, i used a switch case, like this:
$panir=$_POST['select1'];
switch ($panir) {
case 'value1':
?>
<select name="select1">
<option value="value1" selected>hot</option>
<option value="value2">popular</option>
<option value="value3" >new</option>
<option value="value4">old</option>
</select>
<?php
break;
case 'value2':
?>
<select name="select1">
<option value="value1">hot</option>
<option value="value2" selected>popular</option>
<option value="value3">new</option>
<option value="value4">old</option>
</select>
<?php
break;}
it works great, but has a big problem, i have another select option with lots of options and i can't add case as number as them, isn't there any solution that options would be selected by a condition? thanks a lot.
Share Improve this question asked Apr 8, 2019 at 6:20 hessam hosseinipourhessam hosseinipour 191 silver badge8 bronze badges1 Answer
Reset to default 0You should have only 1 select. Before the ">" of each option you can add
<?php echo ( $_POST['select1'] == 'value' ? 'selected' : '' ); ?>
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionI have a select option like this
<select name="select1">
<option value="value1">hots</option>
<option value="value2">popular</option>
<option value="value3" >new</option>
<option value="value4">old</option>
</select>
when a user select one option in the next loading the selected option again is the first one (value1), i managed to find an official solution, i used a switch case, like this:
$panir=$_POST['select1'];
switch ($panir) {
case 'value1':
?>
<select name="select1">
<option value="value1" selected>hot</option>
<option value="value2">popular</option>
<option value="value3" >new</option>
<option value="value4">old</option>
</select>
<?php
break;
case 'value2':
?>
<select name="select1">
<option value="value1">hot</option>
<option value="value2" selected>popular</option>
<option value="value3">new</option>
<option value="value4">old</option>
</select>
<?php
break;}
it works great, but has a big problem, i have another select option with lots of options and i can't add case as number as them, isn't there any solution that options would be selected by a condition? thanks a lot.
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionI have a select option like this
<select name="select1">
<option value="value1">hots</option>
<option value="value2">popular</option>
<option value="value3" >new</option>
<option value="value4">old</option>
</select>
when a user select one option in the next loading the selected option again is the first one (value1), i managed to find an official solution, i used a switch case, like this:
$panir=$_POST['select1'];
switch ($panir) {
case 'value1':
?>
<select name="select1">
<option value="value1" selected>hot</option>
<option value="value2">popular</option>
<option value="value3" >new</option>
<option value="value4">old</option>
</select>
<?php
break;
case 'value2':
?>
<select name="select1">
<option value="value1">hot</option>
<option value="value2" selected>popular</option>
<option value="value3">new</option>
<option value="value4">old</option>
</select>
<?php
break;}
it works great, but has a big problem, i have another select option with lots of options and i can't add case as number as them, isn't there any solution that options would be selected by a condition? thanks a lot.
Share Improve this question asked Apr 8, 2019 at 6:20 hessam hosseinipourhessam hosseinipour 191 silver badge8 bronze badges1 Answer
Reset to default 0You should have only 1 select. Before the ">" of each option you can add
<?php echo ( $_POST['select1'] == 'value' ? 'selected' : '' ); ?>
本文标签: menuschoose selected for select option with condition
版权声明:本文标题:menus - choose selected for select option with condition 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745616780a2159337.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论