Skip to main content
Inspiring
July 9, 2009
Question

Javascript change property of PHP variable according to date in list menu selection

  • July 9, 2009
  • 1 reply
  • 630 views

I'm creating a booking form which selects prices and dates from a Mysql databse according to the code transported in the URL.

I have successfully got the form to display dates for this year and next year in a drop down menu/list form item.

However, I would like to change the price according to what year the selected date falls in.

The key variable that needs to change is this $coursefee

If a date in 2009 date (e.g. 2009-10-12) is selected the varibiable $coursefee would change to be

<?php $coursefee=$row_rs_course['price09'];?>

And if a date like 2010-10-12 is selected the varibiable $coursefee would change to be

<?php $coursefee=$row_rs_course['price10'];?>

To complicate matters the menu is dyamically populated too:

<select name="dates" class="course" id="dates">
<?php
do { 
?>

<?php

$date1 = strftime("%d %b",strtotime($row_rs_dates['start_date']));                       
$date2 = strftime("%d %b %Y",strtotime($row_rs_dates['finish-date']));

?>

<option value="<?php echo($date1." - ".$date2); ?>"><?php echo($date1." - ".$date2);?></option>
                   
} while ($row_rs_dates = mysql_fetch_assoc($rs_dates));
  $rows = mysql_num_rows($rs_dates);
if($rows > 0) {
mysql_data_seek($rs_dates, 0);
$row_rs_dates = mysql_fetch_assoc($rs_dates);

</select>

I'm pretty sure the answer lies in the murky world of javascript but unfortunately I haven't the first clue about javascript.

Can anyone help me with this?

Cheers

Dave

This topic has been closed for replies.

1 reply

David_Powers
Inspiring
July 10, 2009

The simple way to handle this is to use a Dreamweaver jump menu to select the year. Use the jump menu to reload the page when the value is changed and pass the year as a URL parameter in the query string. Then use the value of the year to filter the recordset to display the correct price.

Inspiring
July 13, 2009

Thanks David,

I can see that would work and I'd have no problems doing that but wouldn't that mean that all the oher data the user had fillled in would dissapear?

There are too many fields I think to transfer everything in the URL and the date selection field is way down the form and I think it would seem pretty odd to have it before name address etc. That's why I thought a javascript solution would be more suitable as it needn't rely on a page refresh.


Cheers

Dave