Php - 需要从更改的复选框中获取值 [英] Php - need to get values from changed checkboxes

查看:71
本文介绍了Php - 需要从更改的复选框中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,免责声明:我的编程背景是C / C ++ / java,过去几年主要是java ...实际上,我很长时间没有触及过C / C ++。我也一直在做PHP,我很喜欢,HTML和JavaScript。我在PHP上比HTML或JavaScript更强大,网页开发对我来说也不是很强大,也许这就是为什么我不得不问。



我有两个下拉菜单,第一个是一对多到第二个。

例如:

主要下拉菜单:国家

第二次下拉:城市

所以,对于美国,我们会有一个城市列表,芝加哥,纽约等。



当我选择国家时,我称之为Ajax PHP代码,从城市表中获取属于该国家/地区的城市,然后在屏幕上的桌面上显示。每个城市都有一个状态列(真或假),如果真,那么它是活动的,它将显示在列表中,如果它的假它将不会显示。

用户可以在他们调用时将复选框的值从true更改为false,反之亦然,以取消激活或激活城市。

当我查看代码(调查)从页面,它没有显示列表,我必须假设没有创建对象,因此我无法获得更改的值。

真正的问题是,如何获取更改后的值,以便我可以仅使用更改的值更新表格吗?



我尝试过的方法:



我试过通过JavaScript获取对象,我可以通过PHP获取值但是它的OLD VALUE,所以如果我将它从checked更改为uncheck ,我没有看到新的未经检查的价值。

我正在编写一个新的JavaScript函数,试图将那些改变的数组放入一个数组中,看看我是否可以调用另一个r PHP Ajax例程使用该数组并相应地更新表中的值。

First, a disclaimer: my background in programming is C/C++/java, mostly java the last few years...actually, I haven't touched C/C++ for a very long time. I have also been doing PHP, which I like a lot, HTML and JavaScript. I am stronger on PHP than HTML or JavaScript, also webpage development is not a strong one for me yet, and maybe that is why I am having to ask.

I have two drop-downs, the first is a one-to-many to the second.
For example:
Main Drop-Down: COUNTRY
Second Drop-Down: CITIES
So, for USA we would have a list of cities from there, Chicago, NY, etc.

When I pick the country I call an Ajax PHP code to get the cities that belong to that country from the "cities" table, then show it on the screen on a table. Each city has a "status" column (true or false), if "true" then it is active and it will show on the list, if its "false" it won't show.
The user can, at the time they call it, change the value of the "checkbox" from "true" to "false" and vice-versa to inactivate or activate a city.
When I look at the code (investigate) from the page, it doesn't show the list, which I have to assume the objects are not being created and thus I cannot get the changed values.
The real issue is, how do I get the changed values so that I may update the table with only those that changed?

What I have tried:

I have tried getting the objects via JavaScript, I can get the value via PHP but its the "OLD VALUE", so if I change it from "checked" to "uncheck", I don't see the new "unchecked" value.
I am writing a new JavaScript function to try to put into an array the ones that change and see if I can call another PHP Ajax routine to use that array and update the values accordingly on the table.

推荐答案

我用来处理复选框的技巧,部分是因为我在用于生成页面的通用SQL驱动方式。大多数每个控件都有一个值属性,但复选框需要检查已检查状态,而不是。



解决方案:有一个隐藏的控件,它的值设置为基础在复选框的状态(0或1)和复选框的onchange事件的偶数。您在隐藏控件中查找值 - 忽略复选框。如果它是一个表单,例如,隐藏的控件获取一个名称,则复选框不会。




There's a trick I use to handle check boxes, partly because I use them in a generic SQL driven fashion to generate pages. Most every control has a value attribute, but check boxes need to be check for the checked state, instead.

Solution: Have a hidden control that has it's value set based upon the checkbox's state (0 or 1) and a even for the checkbox's onchange event. You look for the value in the hidden control - ignoring the checkboxes. If it's a form, for example, the hidden control gets a name, the checkbox doesn't.



这篇关于Php - 需要从更改的复选框中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆