SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Dependable select boxes problem
-
Feb 16, 2005, 06:52 #1
- Join Date
- Feb 2004
- Location
- Ljubljana
- Posts
- 191
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Dependable select boxes problem
Hi there....
I have a two select boxes(project and tasks)...and when someone changes project the second select is populated with tasks with this function..
PHP Code:function setOptions(selectRef, optArray) {
if(selectRef!=null && optArray!=null) {
var optsRef = selectRef.options;
// Clear old options
optsRef.length = 0;
// Insert new options
for (var i = 0 ; i < optArray.length-1 ; i += 2) {
var opt = new Option(optArray[i],optArray[i+1]); // text,value
optsRef[optsRef.length] = opt;
}
}
}
project[project_id] = new Array("-----","0", "task_name", "task_id", "task2_name, "task2_id"....)
and the HTML looks like this...
<select name="project_id" onchange="setOptions(document.aktivnosti.elements['task_id'], project[this.options[this.selectedIndex].value]);" class="inputSel">
and task_id select is empty because it's populated from the above array...
<select name="task_id" class="inputSel"></select>
so far so good....
But the problems starts when the users needs to change some settings for one task than the project has to be selected(that's working ok) and task has to be selected....I'm setting the task like so...
document.aktivnosti.task_id.selectedIndex = {$item->task_id};
but as you see above the task_id select box is "empty" and this command cannot set the desired task to be selected...
So what I get is this....when users clicks on one row the whole row is "opened" for editing....and as you see the task (NALOGA) is empty when is should be selected.....
Any pointers would be great..TIA...exit(0);
-
Feb 16, 2005, 07:28 #2
- Join Date
- Feb 2004
- Location
- Ljubljana
- Posts
- 191
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Huh...got it
I changed that setOptions function and added the third parameter selectedTask....
PHP Code:function setOptions(selectRef, optArray, selectedTask) {
if(selectRef!=null && optArray!=null) {
var optsRef = selectRef.options;
// Clear old options
optsRef.length = 0;
// Insert new options
for (var i = 0 ; i < optArray.length-1 ; i += 2) {
var opt = new Option(optArray[i],optArray[i+1]); // text,value
optsRef[optsRef.length] = opt;
// I ADDED THIS
if(selectedTask == optArray[i+1])
opt.selected = true;
}
}
}
exit(0);
-
Feb 16, 2005, 11:19 #3
- Join Date
- Nov 2004
- Location
- Portsmouth UK
- Posts
- 1,499
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Glad you fixed it but suggest that you check out this link
http://www.js-examples.com/forum/viewtopic.php?t=779
Bookmarks