Hi,
I have a problem to create a form with a dynamic dropdown list. I search on the net but i never find how to do this (or the answer is not developped).
In fact i have a form with 2 dropdown list.
In the first, the list have 3 choices : color, shape, name.
The second list must contains only color (black/white/green) if color is choosed before, shape (square,circle) if shape is choosed before, etc..
How can i do that ? I know how to create a form with 2 dropdown list, i think i need to change the php code after for resolving my problem but how ?.
I need help.
David
I have a problem to create a form with a dynamic dropdown list. I search on the net but i never find how to do this (or the answer is not developped).
In fact i have a form with 2 dropdown list.
In the first, the list have 3 choices : color, shape, name.
The second list must contains only color (black/white/green) if color is choosed before, shape (square,circle) if shape is choosed before, etc..
How can i do that ? I know how to create a form with 2 dropdown list, i think i need to change the php code after for resolving my problem but how ?.
I need help.
David
Ok, i found the solution using this thread : http://www.chronoengine.com/forums.html?cont=posts&f=5&t=12413&p=22658&hilit=dynamic+drop+down#p22658 thanks
My code works perfectly with two dynamic drop down list, but in fact i need three dynamic drop down list.
When i change elements in my first list, the second is changed correctly but when i change the second the last is not modified.
(the elements of my drop down list are from sql queries).
This is my code html :
and my javascript code :
I think my error is in my change_categorie function, when i declare type, but i'm not sure...
I can give a backup of my database by pm if necessary.
My code works perfectly with two dynamic drop down list, but in fact i need three dynamic drop down list.
When i change elements in my first list, the second is changed correctly but when i change the second the last is not modified.
(the elements of my drop down list are from sql queries).
This is my code html :
<?php //Déclaration de variables utiles (valeurs des fieldid)
$fieldid_departement = 59;
$fieldid_type = 67;
$fieldid_type_sport = 70;
$fieldid_type_sorties = 71;
$fieldid_type_loisirs = 72;
$fieldid_activite_sportcombat = 73;
$fieldid_activite_sportnautique = 75;
$fieldid_activite_sportequestre = 74;
?>
<!-- GESTION DU TYPE -->
<div id='type'>
<select id='type_liste' name='type_liste' style='width:160px;' onChange='change_type();'>
<?php
$resultat_type = mysql_query('SELECT fieldtitle FROM jos_comprofiler_field_values WHERE fieldid ='.$fieldid_type);
while($row = mysql_fetch_array($resultat_type))
{
echo '<option >'.$row["fieldtitle"].'</option>';
}
?>
</select>
</div>
<div id='Sports' class='select' style='display:block;'>
<select id='typeliste' name='typeliste' style='width:160px;' onChange='change_categorie()'>
<?php
$resultat_typelistsport = mysql_query('SELECT fieldtitle FROM jos_comprofiler_field_values WHERE fieldid ='.$fieldid_type_sport);
while($row = mysql_fetch_array($resultat_typelistsport))
{
echo '<option >'.$row["fieldtitle"].'</option>';
}
?>
</select>
</div>
<div id='Sorties' class='select' style='display:none;'>
<select id='typeliste' name='typeliste' style='width:160px;' onChange='change_categorie()'>
<?php
$resultat_typelistsorties = mysql_query('SELECT fieldtitle FROM jos_comprofiler_field_values WHERE fieldid ='.$fieldid_type_sorties);
while($row = mysql_fetch_array($resultat_typelistsorties))
{
echo '<option >'.$row["fieldtitle"].'</option>';
}
?>
</select>
</div>
<div id='Loisirs' class='select' style='display:none;'>
<select id='typeliste' name='typeliste' style='width:160px;' onChange='change_categorie()'>
<?php
$resultat_typelistloisirs = mysql_query('SELECT fieldtitle FROM jos_comprofiler_field_values WHERE fieldid ='.$fieldid_type_loisirs);
while($row = mysql_fetch_array($resultat_typelistloisirs))
{
echo '<option >'.$row["fieldtitle"].'</option>';
}
?>
</select>
</div>
<!-- FIN GESTION DU TYPE -->
<!-- GESTION DE LA CATEGORIE -->
<div id='Sport de combat' class='selectcategorie' style='display:block;'>
<select id='typelisteactivite' name='typelisteactivite' style='width:160px;'>
<?php
$resultat_categorie_combat = mysql_query('SELECT fieldtitle FROM jos_comprofiler_field_values WHERE fieldid ='.$fieldid_activite_sportcombat);
while($row = mysql_fetch_array($resultat_categorie_combat))
{
echo '<option >'.$row["fieldtitle"].'</option>';
}
?>
</select>
</div>
<div id='Sport équestre' class='selectcategorie' style='display:none;'>
<select id='typelisteactivite' name='typelisteactivite' style='width:160px;'>
<?php
$resultat_categorie_equestre = mysql_query('SELECT fieldtitle FROM jos_comprofiler_field_values WHERE fieldid ='.$fieldid_activite_sportequestre);
while($row = mysql_fetch_array($resultat_categorie_equestre))
{
echo '<option >'.$row["fieldtitle"].'</option>';
}
?>
</select>
</div>
<!-- FIN GESTION CATEGORIE -->
and my javascript code :
function change_type()
{
var type = $('type_liste');
var selects = $$('div.select');
for ( var i = 0; i < selects.length; i++ ) {
if (selects[i].id == type.value ) {
selects[i].style.display = 'block';
} else {
selects[i].style.display = 'none';
}
}
}
function change_categorie()
{
var type = $('typeliste');
var selects = $$('div.selectcategorie');
for ( var i = 0; i < selectcategorie.length; i++) {
if (selects[i].id == type.value ) {
selects[i].style.display = 'block';
} else {
selects[i].style.display = 'none';
}
}
}
I think my error is in my change_categorie function, when i declare type, but i'm not sure...
I can give a backup of my database by pm if necessary.
Ok i find the solution, you can use this thread for help for example. (ajax is used here)
http://siddh.developpez.com/articles/ajax/#LIV-A
part IV/IV/a.
This is a french webpage.
http://siddh.developpez.com/articles/ajax/#LIV-A
part IV/IV/a.
This is a french webpage.
This topic is locked and no more replies can be posted.