I_G
I_G

Reputation: 413

Insert multiples values in the value of the checkbox

What I want is to insert multiple values in the value of my checkbox and send it to my function myAlert(this) in only one String like "code_dateAdded_..."

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

the value should be like this value="355422_2015-07-30 03:00:16"

I tried to insert like that but when I do an echo on my value I only get the value of $donnees['code'] and not following values like the underscore and $donnees['dateAdded']

The function :

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();
            }
        }

And in myAlert.php I only do an echo of the parametre :

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

Is it possible to do like this and if not how can I do it

Thanks

Upvotes: 0

Views: 56

Answers (1)

Sina
Sina

Reputation: 775

You must try passing a string to the function in onclick, so it will be

onclick="myAlert(this.value)"

and accordingly, just treat the value passed as a string in your function.

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

As for converting your data, you should have:

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

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

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

to convert everything to a string.

Upvotes: 3

Related Questions