Dear colleagues, I have a problem working with forms in PHP.
I have a SELECT tag to choose one item, and in the same form I have another SELECT tag whose options depend on which item was selected in the first one.
How can I do that? Thanks!
Forms in PHP
Moderator: General Moderators
Re: Forms in PHP
Define "depend on".
Also, what's your code?
Also, what's your code?
Re: Forms in PHP
Thanks for your fast reply,
I am still thinking about my code but I'll try to explain:
So on the second select I need to know which item of the first one was selected.
Thanks
I am still thinking about my code but I'll try to explain:
Code: Select all
<select name="temp">
<?php $res2=mysql_query("SELECT * FROM Temporadas");
for($i=0;$i<mysql_num_rows($res2);$i++)
{ ?> <option value="<?php echo mysql_result($res2,$i,"Temporada");?>"><?php echo $i;?></option> <?php } ?>
</select>
<select name="comp">
<?php $res3=mysql_query("SELECT * FROM Competiciones WHERE Id_temp=[color=#FF0000]HERE IS WHERE I NEED THE PREVIOUS ITEM[/color]");
for($i=0;$i<mysql_num_rows($res3);$i++)
{ ?> <option value="<?php echo mysql_result($res3,$i,"Id_competicion");?>"><?php echo $i;?></option> <?php } ?>
</select>Thanks
Re: Forms in PHP
You'd have to submit the form once they select the first option. You can put this on the select element:
Then you can check if they have chosen something like this:
I'd personally use javascript, but if you're not familiar with it (or you prefer PHP), then you should probably just do this.
You might also want to echo back the post data into the inputs so that the user's data is preserved
Code: Select all
onchange="document.forms['formid'].submit();"Code: Select all
if(isset($_POST['the_select_element']))
{
//display the relative select options here
}You might also want to echo back the post data into the inputs so that the user's data is preserved
Re: Forms in PHP
Thank you, it was very helpful! 
Re: Forms in PHP
Cool, no problem 