changing dropdown based on selected radio button
Posted: Fri Aug 06, 2010 4:58 am
I've been struggling with this piece of code for a good couple of days now. What I'm trying to do it change the options of a drop down list depending on which radio button is selected. What I'm having trouble with is passing the variable from the radio button to form link to read. Here's the code below:
The piece of code is linked to the php/html below where the code above is form.php:
I've tried a var_dump on the $_POST['web']. Before the radio button is selected it produces NULL and After a radio button is selected NULL still appears.
Any help would be apprieciated. Thanks,
Stow
Code: Select all
<?php
$connection = mysql_connect("server","user","pass");
$db=mysql_select_db("db", $connection);
$furniture = "SELECT furniture FROM items";
$sql = mysql_query($furniture) or die(mysql_error());
while ($row = mysql_fetch_array($sql))
{
echo "<input type=\"radio\" name=\"web\" value='".$row['furniture']."'>".$row['furniture']."</input>";
}
$furn = $_POST['web'];//The problem??
$dir = $furn."/upload";
echo "<br /><select name=\"up\">";
if(file_exists($dir))
{
if($dh=opendir($dir))//Opening directory
{
if(($dhf = scandir($dir)) && (count($dhf) == 2))
{
echo "<option value=\"empty\">Directory is empty!</option>";
}
else
{
while (($sd = (readdir($dh))) !== false)//while the directory being read is
{
if($sd != "." && $sd != "..")
{
echo "<option value='".$sd."'>".$sd."</option>";
}
}
}
}
}
echo "</select>";
echo"<br />If your can find the type of furniture you are looking for create a new one:";
echo"<br /><input type=\"text\" name=\"newFolder\" />";
?>
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Upload File</title>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="104857600" />
File:<input type="file" name="file" /><br />
<?php include 'form.php'; ?><br /><!--lists furniture depending on type-->
<input type="submit" name="submit" />
</form>
</body>
</html>
Any help would be apprieciated. Thanks,
Stow