Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with dynamic select box 2

Status
Not open for further replies.

rmagan

Programmer
Jun 3, 2003
35
US
I have some code that re-sets values in a select box based on what was chosen in a radio group. 2 problems:

1) When I change my radio option, the select box re-sets its values but it jumps from the radio option I selected to the first radio option (try changing from radio 'ADD' to 'DROP' to see).

2) It is not re-setting all the values in the select box. It seems to leave the 1st entry from the old set (when chaging from 'ADD' to 'DROP' the '01' entry should be removed. Am i missing something?

<HTML>
<HEAD>
</HEAD>
<BODY>

<FORM name=&quot;maint_student_schedule&quot; action=&quot;maint_student_schedule&quot; method=&quot;post&quot;>
<TABLE width=&quot;100%&quot; border=&quot;0&quot; cellspacing=0 cellpadding=2 id=&quot;student_schedule&quot;>
<TD ALIGN=&quot;CENTER&quot;> <FONT CLASS=&quot;PortletText1&quot;>
<input type=&quot;radio&quot; NAME=&quot;sched_type&quot; id=&quot;sched_type1&quot; VALUE=&quot;ADD&quot; onFocus=&quot;redirect(this.id,this.value);&quot; Checked> Add &nbsp;&nbsp
</TD>
<TD ALIGN=&quot;CENTER&quot;> <FONT CLASS=&quot;PortletText1&quot;>
<input type=&quot;radio&quot; NAME=&quot;sched_type&quot; id=&quot;sched_type2&quot; VALUE=&quot;DEL&quot; onFocus=&quot;redirect(this.id,this.value);&quot; > Drop &nbsp;&nbsp
</TD>
<TD ALIGN=&quot;RIGHT&quot;> <FONT CLASS=&quot;PortletText1&quot;>
<input type=&quot;radio&quot; NAME=&quot;sched_type&quot; id=&quot;sched_type3&quot; VALUE=&quot;CHG&quot; onFocus=&quot;redirect(this.id,this.value);&quot; > Change &nbsp; &nbsp
</TD>
<TD ALIGN=&quot;RIGHT&quot;> <FONT CLASS=&quot;PortletText1&quot;>
<SELECT name=&quot;sched_choice&quot; id=&quot;sched_choice1&quot;>
<OPTION value=01>01 &nbsp;&nbsp (07:00-08:44)
<OPTION value=02>02 &nbsp;&nbsp (08:45-09:25)
<OPTION value=03>03 &nbsp;&nbsp (09:25-10:10)
<OPTION value=04>04 &nbsp;&nbsp (10:10-10:55)
<OPTION value=05>05 &nbsp;&nbsp (10:55-11:40)
<OPTION value=06>06 &nbsp;&nbsp (11:40-12:25)
<OPTION value=07>07 &nbsp;&nbsp (12:25-13:09)
<OPTION value=08>08 &nbsp;&nbsp (13:10-16:00)
</SELECT>
</TD>
</TR>
</TABLE>
<script language=&quot;javascript&quot;>

function redirect(p_param_id1,p_value) {
temp = document.getElementById(document.maint_student_schedule.sched_choice1.id);
x = document.getElementById(document.maint_student_schedule.sched_choice1.id).options.selectedIndex;
for (m = temp.options.length - 1; m > 0; m--) temp.options[m] = null;
if (p_value =='ADD') {

insertOptionAt(temp, new Option(&quot;01 (07:00-08:44)&quot;,&quot;01&quot;));

insertOptionAt(temp, new Option(&quot;02 (08:45-09:25)&quot;,&quot;02&quot;));

insertOptionAt(temp, new Option(&quot;03 (09:25-10:10)&quot;,&quot;03&quot;));

insertOptionAt(temp, new Option(&quot;04 (10:10-10:55)&quot;,&quot;04&quot;));

insertOptionAt(temp, new Option(&quot;05 (10:55-11:40)&quot;,&quot;05&quot;));

insertOptionAt(temp, new Option(&quot;06 (11:40-12:25)&quot;,&quot;06&quot;));

insertOptionAt(temp, new Option(&quot;07 (12:25-13:09)&quot;,&quot;07&quot;));

insertOptionAt(temp, new Option(&quot;08 (13:10-16:00)&quot;,&quot;08&quot;));
} else {

insertOptionAt(temp, new Option(&quot;112-001 (ENGLISH 10)&quot;,&quot;112001&quot;));

insertOptionAt(temp, new Option(&quot;919-002 (PE10/HEALT)&quot;,&quot;919002&quot;));

insertOptionAt(temp, new Option(&quot;507-003 (BIOLOGY)&quot;,&quot;507003&quot;));

insertOptionAt(temp, new Option(&quot;507-003 (BIOLOGY)&quot;,&quot;507003&quot;));

insertOptionAt(temp, new Option(&quot;317-002 (ALG.II (H))&quot;,&quot;317002&quot;));
}
return true;}

function insertOptionAt (select,option) {
select.options[select.options.length] = option;
}
</script>
</TBODY>
</FORM>
</TABLE>

</BODY>
</HTML>
 
I changed this
for (m = temp.options.length - 1; m > 0; m--) temp.options[m] = null;

to
this
for (m = temp.options.length - 1; m >= 0; m--) temp.options[m] = null;

the select starts at 0.

I also put fixed width for the table to prevent jumping around.

try this:

<HTML>
<HEAD>
</HEAD>
<BODY>

<FORM name=&quot;maint_student_schedule&quot; action=&quot;maint_student_schedule&quot; method=&quot;post&quot;>
<TABLE width=&quot;100%&quot; border=&quot;0&quot; cellspacing=0 cellpadding=2 id=&quot;student_schedule&quot;>
<TD ALIGN=&quot;CENTER&quot; width=&quot;25%&quot;> <FONT CLASS=&quot;PortletText1&quot;>
<input type=&quot;radio&quot; NAME=&quot;sched_type&quot; id=&quot;sched_type&quot; VALUE=&quot;ADD&quot; onFocus=&quot;redirect(this.id,this.value);&quot; Checked> Add
</TD>
<TD ALIGN=&quot;CENTER&quot; width=&quot;25%&quot;> <FONT CLASS=&quot;PortletText1&quot;>
<input type=&quot;radio&quot; NAME=&quot;sched_type&quot; id=&quot;sched_type&quot; VALUE=&quot;DEL&quot; onFocus=&quot;redirect(this.id,this.value);&quot; > Drop
</TD>
<TD ALIGN=&quot;RIGHT&quot; width=&quot;25%&quot;> <FONT CLASS=&quot;PortletText1&quot;>
<input type=&quot;radio&quot; NAME=&quot;sched_type&quot; id=&quot;sched_type&quot; VALUE=&quot;CHG&quot; onFocus=&quot;redirect(this.id,this.value);&quot; > Change
</TD>
<TD ALIGN=&quot;RIGHT&quot; width=&quot;25%&quot;> <FONT CLASS=&quot;PortletText1&quot;>
<SELECT name=&quot;sched_choice&quot; id=&quot;sched_choice1&quot; >
<OPTION value=01>01 (07:00-08:44)
<OPTION value=02>02 (08:45-09:25)
<OPTION value=03>03 (09:25-10:10)
<OPTION value=04>04 (10:10-10:55)
<OPTION value=05>05 (10:55-11:40)
<OPTION value=06>06 (11:40-12:25)
<OPTION value=07>07 (12:25-13:09)
<OPTION value=08>08 (13:10-16:00)
</SELECT>
</TD>
</TR>
</TABLE>
<script language=&quot;javascript&quot;>

function redirect(p_param_id1,p_value) {

temp = document.getElementById(document.maint_student_schedule.sched_choice1.id);
x = document.getElementById(document.maint_student_schedule.sched_choice1.id).options.selectedIndex;
for (m = temp.options.length - 1; m >= 0; m--) temp.options[m] = null;
if (p_value =='ADD') {

insertOptionAt(temp, new Option(&quot;01 (07:00-08:44)&quot;,&quot;01&quot;));

insertOptionAt(temp, new Option(&quot;02 (08:45-09:25)&quot;,&quot;02&quot;));

insertOptionAt(temp, new Option(&quot;03 (09:25-10:10)&quot;,&quot;03&quot;));

insertOptionAt(temp, new Option(&quot;04 (10:10-10:55)&quot;,&quot;04&quot;));

insertOptionAt(temp, new Option(&quot;05 (10:55-11:40)&quot;,&quot;05&quot;));

insertOptionAt(temp, new Option(&quot;06 (11:40-12:25)&quot;,&quot;06&quot;));

insertOptionAt(temp, new Option(&quot;07 (12:25-13:09)&quot;,&quot;07&quot;));

insertOptionAt(temp, new Option(&quot;08 (13:10-16:00)&quot;,&quot;08&quot;));
} else {

insertOptionAt(temp, new Option(&quot;112-001 (ENGLISH 10)&quot;,&quot;112001&quot;));

insertOptionAt(temp, new Option(&quot;919-002 (PE10/HEALT)&quot;,&quot;919002&quot;));

insertOptionAt(temp, new Option(&quot;507-003 (BIOLOGY)&quot;,&quot;507003&quot;));

insertOptionAt(temp, new Option(&quot;507-003 (BIOLOGY)&quot;,&quot;507003&quot;));

insertOptionAt(temp, new Option(&quot;317-002 (ALG.II (H))&quot;,&quot;317002&quot;));
}
return true;}

function insertOptionAt (select,option) {
select.options[select.options.length] = option;
}
</script>
</TBODY>
</FORM>
</TABLE>

</BODY>
</HTML>
 
You don't need a loop to clear the values, just set the select length to zero.

Adam
while(ignorance==true){perpetuate(violence,fear,hatred);life--};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top