简体   繁体   English

在不提交表单的情况下在单选框上设置php变量

[英]set php variable on radio box without submitting the form

i have a set of radio boxes, and a select list. 我有一组收音机,还有一个选择列表。 The radio boxes represents the objects, and the select list represents the number of pieces for every object (to be bought). 单选框表示对象,选择列表表示每个对象(要购买)的件数。 i want to synchronise the stock with the select list. 我想将库存与选择列表同步。 meaning that, if i choose the first product and i have only 6 products in the stock, i want the maximum value in the select list to be 6. if i choose the second and i have only 2 products in the stock, i want the maximum to be 2. 这意味着,如果我选择第一个产品,而我的库存中只有6个产品,我希望选择列表中的最大值为6。如果我选​​择第二个产品,而我只有2个产品,我希望最大值为2。

How do i synchronise the select list with the radio boxes? 如何将选择列表与单选框同步?

thanks! 谢谢!

As PHP is a dependent server-side script, this would be very hard to do, if not impossible with just PHP. 由于PHP是从属服务器端脚本,因此很难做到这一点,即使仅使用PHP也不是不可能。 I see two options: 我看到两个选择:

  1. Use a bit of Javascript to refresh the page whenever a form element is updated, and use those corresponding values in a PHP script to update the form with the new values. 每当表单元素被更新时,使用一点Javascript刷新页面,并在PHP脚本中使用那些相应的值来用新值更新表单。

  2. Use JQuery or AJAX to request a PHP script that will do the same thing. 使用JQuery或AJAX请求将执行相同操作的PHP脚本。 Same in concept, but wont refresh the page each time. 概念相同,但不会每次都刷新页面。

You need to write javascript that loads with the page, that will limit the amounts for those fields. 您需要编写随页面加载的javascript,这将限制这些字段的数量。 The javascript would be created in your php and inserted into the page on load. javascript将在您的php中创建,并在加载时插入到页面中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM