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 and call the set_time_hour java script function in order to change then the next drop down (this.value should be the value of the next dropdown.
If you pass just the this keyword to the set_time_hour function (instead of this.value),you can then get the selectedIndex property and set the other select box to have the same selected index.
Hey Paul, thank you very much for your quick reply. This is not what I mean. The right value is submittted to the set_time_hour function. The problem is that
is not changing the next field. I attached a screenshot to this document to show which field what I want to change. The fielt on top is the one that is providing the info to call set_time_hour function e.g. ‘12’ which is the value that the next field should have and 2_start_time_id which is the name of the next select field (the one that is also marked in the attachment).
I think the javascript document.getElementById(next_field).value = hour_value; is wrong.
You cannot use a value to set the selected option of a dropdown box. It is the selectedIndex property that you need to set instead.
That can be done in a number of different ways.
The preferred technique is to pass a reference to the current select field to the function, so that from the function you can then get the value with select.value or the selectedIndex with select.selectedIndex
That way you can set the selectedIndex property of the next field based on the selectedIndex of the current select field.
There are a couple of reasons why that could be the case.
The selected index needs to be accessed on both sides of the assignment. and the nextfield variable seems like it is the string value of an identifier.
You’ve renamed the function property from field to initialfield, so you need to make that change to the same variable at the start of the statement too.
Also where you have “form1”, that is not a reference to a named field. What that actually is, is a reference to the “form” property that naturally exists on all form fields, which references the form that the field is in.
thank you so much for your help and all your efforts! It is now working! Without your help I wouldnt have made it and I also would have understood it! For some reasons this has been trickier than the last problems I encountered. Anyhow! Thanks!