Jump to content

Need help with dynamic select form


Recommended Posts

Hi, sorry for being a newbie, but I need help setting up a dynamic form.  The form will be a reservation type form.  I have a single table, which I will post below.  What I am looking to do is choose a month from a select box and then have it populate another select box with the available dates.


Here is my table info from mysql...

CREATE TABLE `daterange` (
  `RID` int(5) NOT NULL auto_increment,
  `DEND` date NOT NULL,
  `MONTH` varchar(50) NOT NULL,
  `DATE` varchar(50) NOT NULL,
  `SITE` varchar(50) NOT NULL,
  `PRICE` varchar(10) NOT NULL,
  `STATUS` varchar(1) NOT NULL default 'A',
  `FNAME` varchar(50) NOT NULL,
  `LNAME` varchar(50) NOT NULL,
  `ADDR1` varchar(50) NOT NULL,
  `ADDR2` varchar(50) NOT NULL,
  `CITY` varchar(50) NOT NULL,
  `STATE` varchar(2) NOT NULL,
  `ZIP` varchar(5) NOT NULL,
  `PHONE1` varchar(3) NOT NULL,
  `PHONE2` varchar(3) NOT NULL,
  `PHONE3` varchar(4) NOT NULL,
  `EMAIL` varchar(50) NOT NULL,


Here is a sample mysql dump...

INSERT INTO `daterange` VALUES(1, '2011-05-15', 'May 2011', '5/15-5/22/11', 'Carterville Pond/Adirondack', '$2625.00', 'N', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '');
INSERT INTO `daterange` VALUES(2, '2011-05-22', 'May 2011', '5/22-5/29/11', 'Carterville Pond/Adirondack', '$2625.00', 'A', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '');
INSERT INTO `daterange` VALUES(3, '2011-05-29', 'May 2011', '5/29-6/5/11', 'Carterville Pond/Adirondack', '$2625.00', 'A', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '');


Finally, here is a php form that I started to develop but it only has a single select box, which works but I wanted another select box that will filter the list down a little...

// script to display all the Available Reservations in the daterange table

// connection information
$hostName = "my_host";
$userName = "my_user";
$password = "my_pass";
$dbName = "my_db";

// make connection to database
mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");

mysql_select_db($dbName) or die("Unable to select database $dbName"); 

// Select all the fields in all the records of the daterange table
$query = "SELECT *
          FROM daterange
          ORDER BY RID, DATE, SITE";
$result = mysql_query($query);

// Determine the number of reservation dates
$number = mysql_numrows($result);

// Create drop-down menu of reservation dates

print "<font size=\"3\" face=\"Arial\"><b>Select Reservation Date:</b>
<form action=\"test.php\" method=\"post\">
<select name=\"RID\">
    <option value=\"\">Choose One</option>";

for ($i=0; $i<$number; $i++) {
     $RID = mysql_result($result,$i,"RID");
     $DATE = mysql_result($result,$i,"DATE");
     $SITE = mysql_result($result,$i, "SITE");
 $PRICE = mysql_result($result,$i, "PRICE");
     print "<option value=\"$RID\">$DATE, $SITE, $PRICE</option>";
print "</select><p align=left><label><font size=\"3\" face=\"Arial\">First Name: <input type=\"text\" name=\"FNAME\" size=\"50\" maxlength=\"50\" tabindex=\"1\"<br>";

print "<p align=left><label>Last Name: <input type=\"text\" name=\"LNAME\" size=\"50\" maxlength=\"50\" tabindex=\"2\"<br>";

print "<p align=left><label>Address Line 1: <input type=\"text\" name=\"ADDR1\" size=\"50\" maxlength=\"50\" tabindex=\"3\"<br>";

print "<p align=left><label>Address Line 2: <input type=\"text\" name=\"ADDR2\" size=\"50\" maxlength=\"50\" tabindex=\"4\"<br>";

print "<p align=left><label>City: <input type=\"text\" name=\"CITY\" size=\"50\" maxlength=\"50\" tabindex=\"5\"<br>";

print "<p align=left><label>State (abbrev.): <input type=\"text\" name=\"STATE\" size=\"2\" maxlength=\"2\" tabindex=\"6\"<br>";

print "<p align=left><label>Zip Code: <input type=\"text\" name=\"ZIP\" size=\"5\" maxlength=\"5\" tabindex=\"7\"<br>";

print "<p align=left><label>Contact Phone Number: (<input type=\"text\" name=\"PHONE1\" size=\"3\" maxlength=\"3\" tabindex=\"8\"";
print "<label>)<input type=\"text\" name=\"PHONE2\" size=\"3\" maxlength=\"3\" tabindex=\"9\"";
print "<label>-<input type=\"text\" name=\"PHONE3\" size=\"4\" maxlength=\"4\" tabindex=\"10\"<br>";

print "<p align=left><label>Email: <input type=\"text\" name=\"EMAIL\" size=\"50\" maxlength=\"50\" tabindex=\"11\"<br>";

print "<p align=left><label>Payment Method: <select name=\"PM\">
    <option value=\"\">Choose One</option>
<option value=\"Visa\">Visa</option>
<option value=\"Mastercard\">Mastercard</option>
<option value=\"Discover\">Discover</option>";

print "</select><p align=left><label>Credit Card Number: <input type=\"text\" name=\"C1\" size=\"4\" maxlength=\"4\" tabindex=\"12\"";
print "<label> <input type=\"text\" name=\"C2\" size=\"4\" maxlength=\"4\" tabindex=\"13\"";
print "<label> <input type=\"text\" name=\"C3\" size=\"4\" maxlength=\"4\" tabindex=\"14\"";
print "<label> <input type=\"text\" name=\"C4\" size=\"4\" maxlength=\"4\" tabindex=\"15\"<br>";

print "<p align=left><label>Expiration Month: <select name=\"EXM\">
    <option value=\"\">Choose One</option>
<option value=\"January\">January</option>
<option value=\"February\">February</option>
<option value=\"March\">March</option>
<option value=\"April\">April</option>	
<option value=\"May\">May</option>
<option value=\"June\">June</option>
<option value=\"July\">July</option>
<option value=\"August\">August</option>
<option value=\"September\">September</option>
<option value=\"October\">October</option>
<option value=\"November\">November</option>
<option value=\"December\">December</option>";

print "</select><p align=left><label> Expiration Year: <select name=\"EXY\">
    <option value=\"\">Choose One</option>
<option value=\"2011\">2011</option>
<option value=\"2012\">2012</option>
<option value=\"2013\">2013</option>
<option value=\"2014\">2014</option>
<option value=\"2015\">2015</option>
<option value=\"2016\">2016</option>
<option value=\"2017\">2017</option>
<option value=\"2018\">2018</option>
<option value=\"2019\">2019</option>
<option value=\"2020\">2020</option>";

print "</select><p align=left><label>Security Code (3 or 4 digits): <input type=\"text\" name=\"CSC\" size=\"4\" maxlength=\"4\" tabindex=\"16\"<br>";

print "<p align=left><input type=\"submit\" value=\"Book Now!\"

print " <input type=\"reset\" value=\"reset\"

// Close the database connection



Sorry this is so long, any help would be appreciated......



Link to comment
Share on other sites

if you wish to populate the second select list based on the value selected [month in this case] list, i would suggest you use ajax to load the second list.

check w3schools for the ajax tutorial and a little bit of javascript could solve your problem. Do message me if you need a sample code.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.