hi everyone

this problem is a cross between php, mysql and javascript so I hope someone can help me

I am basically trying to create an online booking for, there are 3 drop down boxes:
- Activity
- Day
- Time

When the user selects an activity, I want the day drop down to be populated with the days of the week.

But when the user selects the day i want to run a query to get the time slots avalible for selected activity on that day, and then populate the time drop down with the times found from the query.

The main problems that I am having is populating the dropdown when a selection is made. I know how to connect to the mysql database and query it but I have no knowledge of javascript and every example I have found is not anotated so I am finding it very hard to understand what is happening

I hopw some one can help

Thanks in advance

Bob

    With a few minor changes this populates one select box from another...

    $query=do_query("SELECT company,category FROM suppliers");
    while(list($company,$category)=mysql_fetch_row($query))
    {
    $category=explode("\n",$category);
    foreach($category as $string)
    {
    $string=trim($string);
    $array .="\"".$company."\",\"".$string."\",";
    }
    }
    $array=substr($array,0,-1);
    ?>
    <script language="JavaScript">
    var supplier_toCategoryMap = new Array(
    <? echo $array;?>);
    function supplier_popCategory(supplier, category) {
    var manCode = supplier.options[supplier.selectedIndex].value;
    var i, j;

    	  j = category.options.length = 1;
    	  category.options.selectedIndex = 0;
    
    	  for(i=0; i<supplier_toCategoryMap.length/2; i++) {
    
    	    if (supplier_toCategoryMap[i*2] == manCode) {
    
    	      category.options.length = j+1;
    	      category.options[j].value = supplier_toCategoryMap[i*2+1];
    	      category.options[j].text = supplier_toCategoryMap[i*2+1];
    	      j += 1;
    	    }
    	  }
    	return;
    	}

    <select name=\"supplier\" onChange=\"supplier_popCategory(this, this.form.category)\" class=\"textbox\">
    <option value=\"\" selected>Please Choose</option>");
    $query=do_query("SELECT company FROM suppliers");
    while(list($company)=mysql_fetch_row($query))
    {
    print("<option value=\"$company\">$company</option>
    ");
    }
    ?>
    </select>

    <select name="category" class="textbox"><option value="" selected>Please Choose</option></select>

    First box is the company, next box is the categories available..

    For working example, see http://www.fish4cars.co.uk - it is the car selector !!

    Cheers,

      Write a Reply...