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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic data in forms 1

Status
Not open for further replies.

Kevin123456

Technical User
Jan 14, 2002
35
0
0
GB
Hi,

Can anyone suggest a way of having a form with a drop-down box that has a couple of options in it and when one of these is selected it populates another drop down box with another set of data? For example:

Select option1 gives options a,b,c,d,e
Select option2 gives options f,g,h,i,j

Thanks
 
This is a strp down version of what I use
It is JavaScript


If your going to build the page dynamically with ASp then you would have to response.write the code shown below. For example: response.Write(&quot;<BODY onLoad = 'init_page();'>&quot;)


stripped down version
'---------------------------------------------------------
<BODY onLoad = &quot;init_page();&quot;>
<FORM NAME=&quot;F1&quot;>

<SELECT id=&quot;DD1&quot;
name=&quot;DD1&quot;
onChange = &quot;fill_list(document.DD2_Array, document.F1.DD1[document.F1.DD1.selectedIndex].value, document.F1.DD2);&quot;>
</SELECT>
<SELECT id=&quot;DD2&quot;
name=&quot;DD2&quot;>
</Select>
</form>
</Body>

<SCRIPT language = &quot;JavaScript&quot;>

function init_page()
{
fill_list(document.DD1_Array, 0, document.F1.DD1, true);
fill_list(document.DD2_Array, document.F1.DD1[document.F1.DD1.selectedIndex].value, document.F1.DD2, false);
}

function fill_list(item_array, parent_item_id, output_select_list, init_flag)
{
output_select_list.length = 0;
for (x = 0; x < item_array.length; x++ )
{
if ( item_array[x] == parent_item_id || init_flag == true )
{
var option1 = new Option(item_array[x+1], item_array[x+2]);
output_select_list.options[output_select_list.length] = option1;
}
x+=2;
}
output_select_list[0].selected = true;
}

//The Arrays that hold the values to display
document.DD1_Array = new Array ('1', 'Value 1', '1',
'2', 'Value 2', '2');

document.DD2_Array = new Array('1', 'Sample 1', '1',
'1', 'Sample 2', '2',
'1', 'Sample 3', '3',
'1', 'Sample 4', '4',
'2', 'Sample 5', '5',
'2', 'Sample 6', '6',
'2', 'Sample 7', '7',
'2', 'Sample 8', '8',
'2', 'Sample 9', '9');

</SCRIPT>
 
Thanks for the response, it worked really well.

A real star reply!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top