Forum de discussion
Forum « Programmation Javascript » (archives)
passage variable javascript dans du php
Envoyé: 21 février 2004, 5h39 par bahia31
salut!!
je voudrais passer des variables javascript à une page php
voici mon code:
<SCRIPT language="javascript">
var oMarques = new Array();
function Marque( id, nom, image )
{
this.id = id;
this.nom = nom;
this.image = image;
this.modeles = new Array();
}
Marque.prototype['Identificateur'] = function() { return this.id; }
Marque.prototype['Nom'] = function() { return this.nom; }
Marque.prototype['Image'] = function() { return this.image; }
Marque.prototype['Modeles'] = function() { return this.modeles; }
Marque.prototype['AjouterModele'] = function( id, nom, image ) { this.modeles.push( new Modele(id,nom,image) ); }
function Modele( id, nom, image )
{
this.id = id;
this.nom = nom;
this.image = image;
}
Modele.prototype['Identificateur'] = function() { return this.id; }
Modele.prototype['Nom'] = function() { return this.nom; }
Modele.prototype['Image'] = function() { return this.image; }
function onSelect_Marque()
{
var id = oListeMarque.options[oListeMarque.selectedIndex].value;
var count, count2;
while (oListeModele.options.length > 0)
oListeModele.removeChild( oListeModele.options[0] );
for (count in oMarques)
if (oMarques[count].Identificateur() == id)
{
for (count2 in oMarques[count].Modeles())
{
var oModele = oMarques[count].Modeles()[count2];
var oOption = document.createElement( 'option' );
oOption.value = oModele.Identificateur();
oOption.text = oModele.Nom();
oListeModele.add( oOption );
}
oListeModele.selectedIndex = 0;
oImageMarque.src = oMarques[count].Image();
onSelect_Modele();
return;
}
}
function onSelect_Modele()
{
var idMarque = oListeMarque.options[oListeMarque.selectedIndex].value;
var idModele = oListeModele.options[oListeModele.selectedIndex].value;
var count, count2;
for (count in oMarques)
if (oMarques[count].Identificateur() == idMarque)
for (count2 in oMarques[count].Modeles())
if (oMarques[count].Modeles()[count2].Identificateur() == idModele)
{
var oModele = oMarques[count].Modeles()[count2];
oImageModele.src = oModele.Image();
return;
}
}
function onLoad()
{
var oMarque;
var count;
<?
$db = mysql_connect("localhost", "root", "");
mysql_select_db(emploi, $db);
$res = mysql_query( 'SELECT * FROM departement ORDER BY id ASC' );
while ($row = mysql_fetch_array( $res ))
{
echo ' oMarque = new Marque( ' . $row['id'] . ', "' . $row['nom'] . '", "' . $row['image'] . '" );';
$res2 = mysql_query( 'SELECT * FROM salle WHERE id = ' . $row['id'] .' order by nom ASC');
while ($row2 = mysql_fetch_array( $res2))
echo ' oMarque.AjouterModele(' . $row2['id'] . ', "' . $row2['nom'] . '", "' . $row2['image'] . '" );';
echo ' oMarques.push( oMarque );' ;
}
?>
for (count in oMarques)
{
var oOption = document.createElement( 'option' );
oOption.value = oMarques[count].Identificateur();
oOption.text = oMarques[count].Nom();
oListeMarque.add( oOption );
}
onSelect_Marque();
}
</SCRIPT>
et les listes déroulantes sont:
<SELECT id=oListeMarque style="FONT-SIZE: 10px; WIDTH: 150px; FONT-FAMILY: Verdana" onchange=onSelect_Marque()>
</SELECT>
<SELECT id=oListeModele style="FONT-SIZE: 10px; WIDTH: 150px; FONT-FAMILY: Verdana" onchange=onSelect_Modele()></SELECT>
aidez moi!!
Réponses
|