Jump to content

on change function


Jamz

Recommended Posts

Hi Guys,

 

In need of some more help.

 

Basically I have two drop down menu's, one with car manufactures and another with car models, basically what I want to do is, when the user selects say "Ford", i want it to output all the cars Ford makes.

 

I have two functions that browse the database for the car manufacturers and the car models:

 

<?php // Function for booking in customer for fitting - outputs all the car makes in the database
function output_make(){
echo '<option></option>'; //Output blank option first
dbconnect(); // Include function for database connection
$result = mysql_query("SELECT make FROM car_make ORDER BY make") or die ('Could not select '.mysql_error());
while($row = mysql_fetch_array($result)){
	echo '<option value="'.$row['make'].'">'.$row['make'].'</option>';
}

}

// Function for booking in customer for fitting - Output car models once car make has been selected in the form
function output_model(){
$make = $_GET['make'];
dbconnect(); // Include function for database connection
$result = mysql_query("SELECT * FROM car_model WHERE car_make='$make' ORDER BY car_model") or die ('Could not select '.mysql_error());
while($row = mysql_fetch_array($result)){
	echo '<option value="'.$row['id'].'">'.$row['car_model'].' ('.$row['year_from'].'-'.$row['year_to'].')</option>';
}
}?>

 

What I am thinking is somehow refresh the page once the car make has been selected (grabbing the rest of the header information - ie page has:

calendar.php?page=booking&day=11&month=3&year=2011

in the URL, and the database needs the day, month, and year... so is there a way to get it to add &make=<option id> on the end of the URL?

 

Hope that makes sense

Link to comment
Share on other sites

Currently banging my head against the wall lol...  :'(

 

Right, the first bit works fine, but does not keep the data in the form, when putting the other bit in, it submits the form to the database, I dont really know javascript, but I think using it is the only way to get what I want it to do.

 

Here's what I have so far:

 

<form action="calendar.php?page=form_submit" method="post" id="book_in">
  <p>
    <label>Time 
      <select name="hour" id="hour">
        <option value="9" selected>9</option>
        <option value="10">10</option>
        <option value="11">11</option>
        <option value="12">12</option>
        <option value="13">13</option>
        <option value="14">14</option>
        <option value="15">15</option>
        <option value="16">16</option>
        <option value="17">17</option>
        <option value="18">18</option>
        <option value="19">19</option>
        <option value="20">20</option>
      </select> 
      :
    </label>
    <label>
      <select name="min" id="min">
        <option value="00">00</option>
        <option value="30">30</option>
      </select>
    </label>
   </p>
   <p><label>Name:<input name="name" type="text" id="name" value="<?php $_POST['name']; ?>"></label></p>
<p><label>Contact:<input name="contact" type="text" id="contact" maxlength="12"></label></p>
<p><label>Car:<select name="make" id="make" onchange="location.href='calendar.php?page=booking&day=<?php echo $day; ?>&month=<?php echo $month; ?>&year=<?php echo $year; ?>&make='+this.value;document.getElementById('book_in').submit();"><?php output_make(); ?></select></label>
	<label>Model:<select name="model" id="model"><?php output_model(); ?></select></label>
<label>Year:<input name="car_year" type="text" id="car_year" size="4" maxlength="4"></label></p>
<p><label>Desc: 
    <select name="desc" id="desc">
      <option selected="selected">Select...</option>
      <option value="Stereo Fit">Stereo Fit</option>
      <option value="Stereo Remove">Stereo Remove</option>
      <option value="Hands Free Kit Fit">Hands Free Kit Fit</option>
      <option value="Hands Free Kit Remove">Hands Free Kit Remove</option>
      <option value="Sub & Amp Fit">Sub & Amp Fit</option>
      <option value="Sub & Amp Remove">Sub & Amp Remove</option>
      <option value="Speaker Fit">Speaker Fit</option>
      <option value="Hardwire">Hardwire</option>
      </select>
  </label>
  </p>
  <p><label>Comments:<br><textarea name="comment" id="comment" cols="45" rows="5"></textarea></label></p>
  <p><label>Customer Paid?<select name="paid" id="paid"><option value="Yes">Yes</option><option value="No">No</option></select></label></p>
    <label>Duration: 
      <select name="duration" id="duration">
        <option value="00:30:00">30 Min</option>
        <option value="01:00:00" selected="selected">1 Hour</option>
        <option value="01:30:00">1 Hour 30 Min</option>
        <option value="02:00:00">2 Hour</option>
        <option value="02:30:00">2 Hour 30 Min</option>
        <option value="03:00:00">3 Hour</option>
      </select> 
    </label></p>
  <input name="date" type="hidden" value="<?php echo $date; ?>" />
  <p><label><input type="submit" name="Submit" id="Submit" value="Submit"></label></p>
</form>

This form gets submitted to a php file which then receives the data using the $_POST function and puts it into a database.

Could the data not just get submitted into the URL and use the $_GET to get the data onchange when selecting make?

Cheers

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.