Jump to content

Its not working!!


ZeroShade

Recommended Posts

I can't seem to get the second box to change depending on what it selected in the first box... whats wrong?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">		<head>				<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />				<title>CompuDeal</title>		</head>		<body>				<h1>CompuDeal</h1>				<p />Welcome to CompuDeal! Please fill out the form below to order a computer product. Our form is simple and fool proof to use.				<form action='index.php' method='POST'>						<p />Computer:						<select name="selectbox1" id="selectbox1" onchange="document.forms[0].submit()">								<option value='c1'>PC</option>								<option value='c2'>Notebook</option>								<option value='c3'>Workstation</option>						</select>						<p />Speed:						<select name='selectbox2' id='selectbox2'>								<?php										$a188 = 'AMD Athlon 1.88GHz';										$a200 = 'AMD Athlon 2.00GHz';										$t220 = 'AMD Turion 2.20GHz';										$o188 = 'AMD Opteron 1.88GHz';										$o200 = 'AMD Opteron 2.00GHz';										if(isset($_POST["selectbox1"]))										{												echo "<option value=''>Speed:</option>";												switch ($_POST["selectbox1"])												{														case 'c1':																echo "<option value='c1speed1'>", $a188, "</option>";																echo "<option value='c1speed2'>", $a200, "</option>";																echo "<option value='c1speed3'>", $t220, "</option>";														break;														case 'c2':																echo "<option value='c2speed1'>", $t220, "</option>";																echo "<option value='c2speed2'>", $o188, "</option>";																echo "<option value='c2speed3'>", $o200, "</option>";														break;														case 'c3':																echo "<option value='c3speed1'>", $t220, "</option>";																echo "<option value='c3speed2'>", $t220, "</option>";																echo "<option value='c3speed3'>", $t220, "</option>";														break;												}										}								?>						</select>						<p />Memory:						<select name='memory'>";								<option value='m1'>512MB</option>								<option value='m2'>1GB</option>								<option value='m3'>2GB</option>						</select>						<p />Space:						<select name='space'>								<option value='h1'>80GB</option>								<option value='h2'>160GB</option>								<option value='h3'>320GB</option>						</select>						<p />All computers are fully loaded and have NVIDIA 7900 GS 256MB graphic cards.			<input type="submit" value="Submit" />				</form>		</body></html>

Link to comment
Share on other sites

What kind of error are you getting? Is it doing anything when you submit it? :)One thing I saw right off the bat, though, is that you need periods, not commas, to concatenate a string.

echo "<option value='c1speed1'>", $a188, "</option>";
You want to use this instead:
echo '<option value=c1speed1>' . $a188 . '</option>';

Another idea would be to have your switch set a variable. That could help in debugging.i.e.

<select name='selectbox2' id='selectbox2'><?php  $box2 = 'Nothing selected!';  if(isset($_POST["selectbox1"]))  {  echo "<option value=''>Speed:</option>";  switch ($_POST["selectbox1"])	{	  case 'c1':		$box2 = "<option value=c1speed1>" . $t220 . "</option>";		break;	  case 'c2':		$box2 = "<option value=c2speed2>" . $t220 . "</option>";		break;	  case 'c3':		$box2 = "<option value=c3speed3>" . $t220 . "</option>";		break;	}  }echo $box2;?></select>

I think there might be far easier ways to do this with JavaScript, though. It may be worth looking into.-Jason

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...