-4
good afternoon, I have an html with some checkbox:
<input type="checkbox" name="item" value="UM" onclick="verificaChecks()">1
<input type="checkbox" name="item" value="DOIS" onclick="verificaChecks()">2
<input type="checkbox" name="item" value="TRES" onclick="verificaChecks()">3
they call javascript (I tried to call php direct but could not, I’m still learning):
<script type="text/javascript">
function verificaChecks() {
var ckitem = document.getElementsByName("item");
var ckarray = [];
var o = 0;
for (var i=0;i<ckitem.length;i++){
if (ckitem[i].checked == true){
ckarray[o] = ckitem[i].value;
o++;
}
}
for (var i=0;i<ckarray.length;i++){
ck = ckarray[i];
alert(ck);
}
}
</script>
in this javascript it shows an alert with all values of checks, I need to pass this array to the php function I have on this page:
<?php
function sProjeto($ckarray){
$projeto = $dados['projeto'];
foreach ($ckarray as $ck):
foreach($projeto as $proj):
if($proj->$ck == 1):
print_r($proj->DESCRICAO);
echo '---';
endif;
endforeach;
endforeach;
}
?>
.. but I cannot pass the javascript array to the php function.
-- Edit I couldn’t do it with Ajax, but I could only do it with Php, created a form and passed the values by json.. vlw
Important you [Dit] your question and explain objectively and punctually the difficulty found, accompanied by a [mcve] of the problem and attempt to solve. To better enjoy the site, understand and avoid closures and negativities worth reading the Stack Overflow Survival Guide in English.
– Bacco