在复选框的值中插入多个值

时间:2015-08-17 07:20:10

标签: php html ajax checkbox

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

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

值应该像这个值=&#34; 355422_2015-07-30 03:00:16&#34;

我试图像这样插入,但当我对我的价值做出回应时,我只得到$ donnees [&#39;代码&#39;]的值,而不是像下划线和$ donnees那样的值[&#39 ; dateAdded&#39;]

功能:

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;

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

由于

1 个答案:

答案 0 :(得分:3)

您必须尝试将字符串传递给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;

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

相关问题