Creare si adaugare sir JSON in caseta input
Scris: Lun Feb 01, 2016
Salut,
Sint contrariat ca un sir json nu este preluat in input (simplificat, testare):
Sirul $aj nu-l pune in id="sirjson" nici daca scot acoladele nici daca mai pun \" \" si nu functioneaza nici ajaxSend () chiar daca pun Unde gresesc?
Sint contrariat ca un sir json nu este preluat in input (simplificat, testare):
Cod: Selectaţi tot
<?php
function formInsert($variabile, $tabela, $clasa){
$numItems = count($variabile);
$i = 0;
$re='';
$aj='{';
$re .='<div id="'.$tabela.'" ><form action="#" class="'.$tabela.'" method="POST" id="'.$tabela.'" style="text-align: right;">Introduceti datele si acest cod : <span style="font-size: 24px;">'.sprintf( $codev).'</span><br/>';
foreach ($variabile as $key => $value) {
$re .= '<label for="'.$value.'">'.$key.'</label><input type="text" name="'.$value.'" id="'.$value.'" autocomplete="off" value="" align="right" style="width: 200px; height: 22px; margin: 3px;" /><br/>';
$aj .= '"'.$value.'"';
if (++$i === $numItems) { if(isset($_POST[$value])) $aj .=' : '.'"'.$_POST[$value].'"'.'}'; else $aj .=' : ""}';}
else {if (isset($_POST[$value])) $aj .=' : '.'"'.$_POST[$value].'"'.', '; else $aj .=' : "", ';}
}
echo $aj; //dupa completarea cimpurilor si submit afiseaza {"nume" : "ion", "prenume" : "vasile", "virsta" : "11"}
$re .= '<input type="text" name="sirjson" id="sirjson" value="'.$aj.'" />'; // pune doar un { in cimp (urmeaza sa-l fac hidden)
$re .= '<input type="submit" name="susr" id="susr" onclick="ajaxSend(this.parentNode.id(\"sirjson\").value);" value="submit" />';
$re .= '</form></div><br/>';
return $re; // afiseaza formularul
}
?>
Cod: Selectaţi tot
ajaxSend(document.getElementById(\"sirjson\").value);