Here is my drop-down form. I have searched and still do not understand how to have a selected drop-down value remain after the cart is updated. Maybe it is because of the PHP in the name value? I would greatly appreciate any help. I believe this has to be done with javascript, but again I am unsure.

这是我的下拉表格。我已经搜索过,但仍然不明白如何在购物车更新后保留选定的下拉值。也许是因为PHP中的名称值?我非常感谢任何帮助。我相信这必须用javascript完成,但我再次不确定。

<select id="quantity" name='.$cart[$x]['ASIN'].'>
<option value=1>1</option>;
<option value=2>2</option>;
<option value=3>3</option>;
</select></td>';

Thanks,

Eric

1 个解决方案

#1


1

As I understand it, you want the selected item to remain selected after the form is submitted and the page is refreshed... in this case you will need to do something like this:

据我了解,您希望在提交表单并刷新页面后保持选中所选项目...在这种情况下,您需要执行以下操作:

<select name='mySelect'>
    <option value=1 <?=(isset($_POST['mySelect'])&&$_POST['mySelect']==1?'selected':'')?>>1</option>

Basically for each option you need to check if that select has a value, and if that value matches the current option ... if so, echo 'selected' which will set that option to the current displayed choice.

基本上对于每个选项,您需要检查该选项是否具有值,以及该值是否与当前选项匹配...如果是,则回显“已选择”,将该选项设置为当前显示的选项。

Unless, you have a situation where you're on like a profile page or something, and you want the user to be able to see his current setting, and still be able to change it... then you would need to do something similar but replace $_POST['mySelect'] with the data from the database. So if you have an array of user data, $data, and one of those values is 'quantity' that corresponds with the select, then you would need:

除非你有一个像个人资料页面那样的情况,并且你希望用户能够看到他当前的设置,并且仍然能够改变它...那么你需要做类似的事情但用数据库中的数据替换$ _POST ['mySelect']。因此,如果您有一组用户数据,$ data,其中一个值是与“数量”对应的“数量”,那么您需要:

<option value=1 <?=($data['quantity']==1?'selected':'')?>>1</option>

更多相关文章

  1. 在指定的div - js内按id计算div的数量
  2. 如何在HTML选择选项列表中保留空间hi
  3. 如何让react-native Picker保持新选择的选项?
  4. 如何为select中的选项创建?
  5. AngularJS(1.5.8) - 如何直接从获取json对象的控制器中填充选择选
  6. FieldErro:无法将关键字'date_added'解析为字段。选项包括:data_ad
  7. ubuntu 16.04 设置选项里面找不到《打印机》和《软件和更新》两
  8. Linux 3.4.39内核编译配置选项介绍
  9. ubi文件系统制作,还是"-c"选项的问题

随机推荐

  1. Android月历控件(DatePicker)和时间控件(Tim
  2. Android - 文件读写操作 总结
  3. Android
  4. Android在开机时自动启动一个应用程序
  5. android 分隔线
  6. EditText小总结
  7. 【Android】Android 代码判断是否获取ROO
  8. Android Gradle 编译问题汇总
  9. Android SDK大连东软镜像地址及地址列表
  10. android manifest.xml中元素含义android