【问题标题】:Insert multiples values in the value of the checkbox在复选框的值中插入多个值
【发布时间】:2015-11-09 18:10:28
【问题描述】:

我想要的是在我的复选框的值中插入多个值,并将其发送到我的函数 myAlert(this) 中,只有一个字符串,如“code_dateAdded_...”

echo '<td><input type="checkbox"  onclick="myAlert(this)" name="code" id="code" value="'.$donnees['code'].'_'.$donnees['dateAdded'].'"/>'.$donnees['code'].'</td>';

值应该是这样 value="355422_2015-07-30 03:00:16"

我尝试这样插入,但是当我对我的值进行回显时,我只得到 $donnees['code'] 的值,而不是像下划线和 $donnees['dateAdded'] 这样的值

功能:

function myAlert(str){
            if (str == "") {
            document.getElementById("valSup").innerHTML = "";
            return;
            } else { 
                if (window.XMLHttpRequest) {
                    // code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp = new XMLHttpRequest();
                } else {
                    // code for IE6, IE5
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange = function() {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                        document.getElementById("valSup").innerHTML = xmlhttp.responseText;
                    }
                }
                xmlhttp.open("GET","myAlert.php?q="+str.value,true);
                xmlhttp.send();
            }
        }

在 myAlert.php 中,我只对参数进行回显:

$q = intval($_GET['q']);        
echo $q;

是否可以这样做,如果不能,我该怎么做

谢谢

【问题讨论】:

  • 你的问题是什么
  • 你在 db 中字段的数据类型是什么?
  • 我的问题是在我的复选框的 value="" 中插入多个参数并将它们放入我的函数中
  • 检查 $donnees 数组的 'dateAdded' 和 'code' 字段是否为空。制作print_r($donnees)并查看结果
  • 它们至少不是空的“代码”,因为当我回显这个 $donnees['code'].'_'.$donnees['dateAdded'] 我只得到 $donnees[ '代码']

标签: php html ajax checkbox


【解决方案1】:

您必须尝试在 onclick 中将字符串传递给函数,所以它将是

onclick="myAlert(this.value)"

因此,只需将传递的值视为函数中的字符串。

xmlhttp.open("GET","myAlert.php?q="+str,true);

至于转换你的数据,你应该有:

$date = $donnees['dateAdded'];
$date = date_format($date, 'Y-m-d H:i:s');

$code = $strval($donnees['code']);

$inputVal = $code.'_'.$date;

将所有内容转换为字符串。

【讨论】:

  • 不行,连下划线都不考虑
  • 即使在表格单元格中也不会将其显示为内容?你试过上面的代码了吗?
  • 是的,我试过了,是的,它显示在表格单元格中,但不在值中。价值的回声仍然只给我 $donnees['code']
  • @sarikaya,现在试试。已编辑。请告诉我。
  • 那么这意味着它已经是一个字符串,尝试注释该行,然后再次检查。 //$date = date_format($date, 'Y-m-d H:i:s');
猜你喜欢
  • 2015-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-20
  • 2021-03-06
  • 2015-02-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多