For,s

second form depenent on first

Page 1 of 1

6 Replies - 1737 Views - Last Post: 11 October 2002 - 05:57 AM Rate Topic: -----

#1 j4h2e  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 17-September 02

For,s

Post icon  Posted 10 October 2002 - 11:26 AM

:P

Ok...I have a question....If wanted to set up a couple drop down selections forms, and have the options within the second one be dependent upon what is selected in the first form, How could I do this?

EX. in the first menu I want computer makes (dell,compaq, ext) I want the second menu to return the models for the make of computer they selected.... :blink:

I have been trying to accomplish this with no success...can somone help me....Please... :crazy:

Is This A Good Question/Topic? 0
  • +

Replies To: For,s

#2 SlashRaid  Icon User is offline

  • Dream.In.Force

Reputation: 1
  • View blog
  • Posts: 2,421
  • Joined: 21-January 02

Re: For,s

Posted 10 October 2002 - 11:32 AM

Does it have to be ASP or could you use a Javascript?
Was This Post Helpful? 0
  • +
  • -

#3 j4h2e  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 17-September 02

Re: For,s

Post icon  Posted 10 October 2002 - 11:35 AM

:P

Java's Ok :rolleyes:

all the pages I've seen that do this are asp pages though so I thought that it would have to be accomplished through asp :lol:


:)
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: For,s

Posted 10 October 2002 - 11:48 AM

j4h2e, on Oct 10 2002, 02:35 PM, said:

all the pages I've seen that do this are asp pages though so I thought that it would have to be accomplished through asp :lol:

ASP pages can contain Javascript, no troubles. Just remember to bracket any functions in the proper javascript tags, and your fine.
Was This Post Helpful? 0
  • +
  • -

#5 SlashRaid  Icon User is offline

  • Dream.In.Force

Reputation: 1
  • View blog
  • Posts: 2,421
  • Joined: 21-January 02

Re: For,s

Posted 10 October 2002 - 12:48 PM

Sorry for my delay.

Here is a simple form along the lines you had talked about:
<HEAD>

<script LANGUAGE="Javascript">
var arrItems1 = new Array();
var arrItemsGrp1 = new Array();

arrItems1[3] = "Gaming";
arrItemsGrp1[3] = 1;
arrItems1[4] = "Pro";
arrItemsGrp1[4] = 1;
arrItems1[5] = "DV";
arrItemsGrp1[5] = 1;

arrItems1[6] = "Presario";
arrItemsGrp1[6] = 2;
arrItems1[7] = "Evo";
arrItemsGrp1[7] = 2;

arrItems1[0] = "Dimension";
arrItemsGrp1[0] = 3;
arrItems1[1] = "Inspiron";
arrItemsGrp1[1] = 3;
arrItems1[2] = "OptiPlex";
arrItemsGrp1[2] = 3;

var arrItems2 = new Array();
var arrItemsGrp2 = new Array();

arrItems2[21] = "8250";
arrItemsGrp2[21] = 0
arrItems2[22] = "4550";
arrItemsGrp2[22] = 0

arrItems2[31] = "8200";
arrItemsGrp2[31] = 1
arrItems2[34] = "2650";
arrItemsGrp2[34] = 1

arrItems2[35] = "GX260";
arrItemsGrp2[35] = 2
arrItems2[36] = "GX50";
arrItemsGrp2[36] = 2

arrItems2[99] = "2001DV";
arrItemsGrp2[99] = 5
arrItems2[100] = "Rosewell";
arrItemsGrp2[100] = 5
arrItems2[57] = "MJ-12";
arrItemsGrp2[57] = 5

arrItems2[101] = "Hive-Mind";
arrItemsGrp2[101] = 3
arrItems2[102] = "Area 51";
arrItemsGrp2[102] = 3

arrItems2[103] = "MJ-12";
arrItemsGrp2[103] = 4
arrItems2[104] = "MJ-12 DDR";
arrItemsGrp2[104] = 4

arrItems2[105] = "8000";
arrItemsGrp2[105] = 6
arrItems2[106] = "6000";
arrItemsGrp2[106] = 6
arrItems2[107] = "4000";
arrItemsGrp2[107] = 6

arrItems2[200] = "300";
arrItemsGrp2[200] = 7
arrItems2[201] = "500";
arrItemsGrp2[201] = 7


function selectChange(control, controlToPopulate, ItemArray, GroupArray)
{
  var myEle;
  var x;
  // Empty the second drop down box of any choices
  for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
  if (control.name == "firstChoice") {
    // Empty third drop down box of any choices
    for (var q=myChoices.thirdChoice.options.length;q>=0;q--) myChoices.thirdChoice.options[q] = null;
 }
  // ADD default choice just in case there are no values
  myEle = document.createElement("option");
  myEle.value = 0;
  myEle.text = "[SELECT]";
  controlToPopulate.add(myEle);
  // Now loop back through the array of individual items.
  // Any containing the same children id are added to
  // the second dropdown
  for ( x = 0; x < ItemArray.length; x++ )
    {
      if ( GroupArray[x] == control.value )
        {
          myEle = document.createElement("option");
          myEle.value = x;
          myEle.text = ItemArray[x];
          controlToPopulate.add(myEle);
        }
    }
}
//  End -->
</script>

</HEAD>
<BODY>

<form name=myChoices>
<table align="center">
<tr>
<td>
<SELECT id=firstChoice name=firstChoice onchange="selectChange(this, myChoices.secondChoice, arrItems1, arrItemsGrp1);">
	<option value=0 SELECTED>[SELECT]</option>
	<option value=1>Alienware</option>
	<option value=2>Compaq</option>
	<option value=3>Dell</option>
</SELECT>
</TD><TD>
<SELECT id=secondChoice name=secondChoice onchange="selectChange(this, myChoices.thirdChoice, arrItems2, arrItemsGrp2);">
</SELECT>
<SELECT id=thirdChoice name=thirdChoice>
</SELECT>
</TD>
</TR>
</TABLE>
</form>
Copy and paste that and see if you can work it for your needs. ;)

Sorry it's not the best display of array usage, but I was in a bit of a hurry and trying to make it to the subject similar to what you had discussed.
Was This Post Helpful? 0
  • +
  • -

#6 j4h2e  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 17-September 02

Re: For,s

Posted 10 October 2002 - 01:03 PM

Thanx SlashRaid... ;)

I allways appriciate your assistance...
:rolleyes:

I also found a similar code @ http://www.javascrip...ion.html#source :ph34r: that is set up the same way your code is....
This proves it works, and I really appriciate your help..

Thanx again.......

:pirate:
J.
Was This Post Helpful? 0
  • +
  • -

#7 SlashRaid  Icon User is offline

  • Dream.In.Force

Reputation: 1
  • View blog
  • Posts: 2,421
  • Joined: 21-January 02

Re: For,s

Posted 11 October 2002 - 05:57 AM

If I remember correctly, that may be where I orginally got it from. It's been a few months and was set different with about 20 selection boxes for what I needed it for.I was able to find that script on a floppy I had started with before adding all my arrays and choices. So there real credit for the code should go to Mr. Berry there.

Hope it works for you. B)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1