Bonjour,
voici mon code :
page : note.php
Code :
session_start();
include('connexion.php');
$a = $_GET['a'];
$select_stg_sql = mysql_query("select * from stagiaire where id_stg = '".$a."'" );
$select_stg = mysql_fetch_array ($select_stg_sql);
$_SESSION['note'] = $select_stg['note'];
Page : ajax.js
Code :
function shownote(stg)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request" );
return;
}
var urla="note.php";
urla=urla+"?a="+stg;
urla=urla+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",urla,true);
xmlhttp.send(null);
}
function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById('note').innerHTML=xmlhttp.responseText;
}
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP" );
}
return null;
}
et la page php qui inclue la page ajax.js:
Code :
<script language="javascript">
function calculresultat()
{
document.getElementById('nt').value = parseFloat(document.getElementById('coeff').value * echo $_SESSION['note'] ; )
}
</script>
if (isset($_POST['action']) && $_POST['action'] == 'notejout') {
);
$sql = 'INSERT INTO `*****` values ("id_stg","note","coeff","resultat" )';
mysql_query($sql);
}
else {
echo '<form method="post" enctype="multipart/form-data" >';
echo '<table >';
echo '<td class="intitula"> Stagiaire: </td><td ><select name="id_stg"
onChange="javascript:shownote(this.value)">';
echo '<option value="" selected="selected"> Selectionnez un Stagiaire </option>';
$selected_stagiaire_sql = mysql_query("SELECT * FROM stagiaire " );
while ($selected_stg = mysql_fetch_array($selected_stagiaire_sql)) {
echo '<option value="'.$selected_stg['id_stg'].'"> '.$selected_stg['nom_stg']." ".$selected_stg['pren_stg'].' </option>';}
echo'</select>';
echo'</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="intitula"> coefficient: </td><td><input class="infose" type="texte" id="coeff" name="coeff" > </td>';
echo '</tr>';
echo '<tr>';
echo '<td class="intitula"> resultat: </td><td>
<input type="texte" id="nt" name="resultat" onFocus="calculresultat();" > </td>';
echo '</tr>';
echo '<tr >';
echo '<td style="text-align: right;"><div id="note" ></div> </td>';
echo '<td><input type="submit" name="button" value="Ajouter"/></td>';
echo '</tr>';
echo '</table>';
echo '</form>';