georgbader
01-14-2012, 07:43 PM
Dear all,
background information:
I did code a timesheet management system for my company with PHP where the user has to submit time entries and has an online form with several start and end times. The start and end times are all simple HTML select option dropdowns. I want that the first End time selection will be the next start time selection. Basically a simple dependency of the dropdown. My approach was that I want to solve this with JavaScript. In my php code I am echoing the following (in this select the end times are the values):
echo "<select class='normal' name='$field_id' onChange=set_time_hour(this.value,'$field_id_js')>";
When the user changes then the end time dropdown the next field (next start time entry) should be changed accordingly.
The javascript looks like this
function set_time_hour(hour_value,next_field){
alert (hour_value);
alert (next_field);
document.getElementById(next_field).value = hour_value;
}
The alert calls are giving me the right values. but the
document.getElementById(next_field).value = hour_value;
is not working. What is wrong there? Do you have an idea?
How can I change the value of a select box with Javascript?
The select box values are already popoluated with PHP so I just want to select the right value.
background information:
I did code a timesheet management system for my company with PHP where the user has to submit time entries and has an online form with several start and end times. The start and end times are all simple HTML select option dropdowns. I want that the first End time selection will be the next start time selection. Basically a simple dependency of the dropdown. My approach was that I want to solve this with JavaScript. In my php code I am echoing the following (in this select the end times are the values):
echo "<select class='normal' name='$field_id' onChange=set_time_hour(this.value,'$field_id_js')>";
When the user changes then the end time dropdown the next field (next start time entry) should be changed accordingly.
The javascript looks like this
function set_time_hour(hour_value,next_field){
alert (hour_value);
alert (next_field);
document.getElementById(next_field).value = hour_value;
}
The alert calls are giving me the right values. but the
document.getElementById(next_field).value = hour_value;
is not working. What is wrong there? Do you have an idea?
How can I change the value of a select box with Javascript?
The select box values are already popoluated with PHP so I just want to select the right value.