I'm working in a project which I have to use several inputs which have to be completed by the client inserting a number. If the number is equal or more than 6, 'aprobada' should appear in the input text, else 'reprobada'. Is it possible to pass variables from php to jquery?
All comments and feedback are welcome :)
Thank you!
CODE JQUERY ,HTML
<script src="jquery-2.1.0.js" type="text/javascript"></script>
<script>
function submitForm() {
$.ajax({type:'POST', url: 'formtronco.php', data:$('#troncocomun').serialize(),
success: function(response) {
$('#troncocomun').find('#aqui').html(response); /*here would be this variable
'$acreditacion[0]' from php to respond in '#aqui'*/
$('#troncocomun').find('#alla').html(response); /*here would be this variable
'$acreditacion[1]' from php to respond in '#alla'*/
}});
return false;
}
</script>
....
<!-- PRIMER SEMESTRE -->
<div class="nivel">NIVEL I</div>
<form class="creditos" onsubmit="return submitForm();" name="troncocomun"
id="troncocomun" method="post" >
<div class="semestre1" >
<table >
<tr>
<td >
UNIDADES DE APRENDIZAJE
</td>
<td>
VALOR EN CRÉDITOS
</td>
<td >
CALIFICACIÓN
</td>
<td >
ACREDITACIÓN
</td>
<td >
CARGA ACADÉMICA
</td>
</tr>
<tr>
<td nowrap id="materia">
ALGEBRA
</td>
<td>
5.62
</td>
<td>
<input type="text" id="1" name="1" size="3px">
</td>
<td id="aqui" name="aqui">
</td>
<td>
Row 1
</td>
</tr>
<tr>
<td nowrap id="materia">
COMPUTACION BASICA I
</td>
<td>
4.5
</td>
<td>
<input type="text" id="2" name="2" size="3px">
</td>
<td id="alla" name="alla">
</td>
<td >
Row 2
</td>
</tr>
<tr>
</table>
<input type="submit" name="enviar" id="enviar" value="Procesar" />
</form>
CODE PHP:
<?php
if(isset($_POST['1']))
{
$acreditacion=array($_POST['1'],$_POST['2']);
if ($acreditacion[0] >=6 ) {
echo "Aprobada";}
else{
echo "Reprobada";
}
if ($acreditacion[1] >=6 ) {
echo "Aprobada";}
else{
echo "Reprobada";
}
}
?>