Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Help with combo boxes??


Message #1 by "Andrew Thomas Crooks" <msc0214@g...> on Thu, 25 Jul 2002 12:27:47
Dear all

Could anyone please help me.  I am pulling infomation from a database, 
basically name and sequnce number but the boxes can only display the name 
and the sequence number can only be passed on and not displayed.  Below is 
what I have so far

At the moment I have got the boxes to display the name and not the number 
but I cant figure out how to pass the number on

eg "David Talbot Rice 544");
ie David Talbot Rice is the name and 544 is the sequence number

Thanks for your time 
Andy

Its probably easy but I am stuck

Heres the script so far


var num_of_cats = 34; // This is the number of categories, including the 
first,blank, category.
//var open_in_newwindow=1; //Set 1 to open links in new window, 0 for no.
var option_array = new Array(num_of_cats);

//The stuff in the array

option_array[0] = new Array("You need to select a category"); // This is 
the first (blank) category. Don't mess with it.

option_array[1] = new Array("-- Select a person --",
 "Francis (Fra) Henry Newbery 1123",
 "David Talbot Rice 544");

option_array[2] = new Array("-- Select a person --",
 "Una McLean 1160",
 "William (Bill) Paterson 722");

option_array[3] = new Array("-- Select a person --",
 "John Mylne 641",
 "Sir George Gilbert Scott 872");

option_array[4] = new Array("-- Select a person --",
 "John Henry Lorimer 1118",
 "Robert MacBryde 1171",
 "Elizabeth Blackadder 877");

option_array[5] = new Array("-- Select a person --",
 "Gavin Maxwell 1133",
 "Rosamunde Pilcher 893");

option_array[6] = new Array("-- Select a person --",
 "John Campbell Hamilton Gordon 748",
 "Victor Alexander John Hope 602");

option_array[7] = new Array("-- Select a person --",
 "Archibald Campbell Tait 1122",
 "Gavin Dunbar 721");

option_array[8] = new Array("-- Select a person --",
 "Sir George Skene 685",
 "James Archibald Hood 1177");

option_array[9] = new Array("-- Select a person --",
 "Hugh Baird 698",
 "Percy Sinclair Pilcher 894");

option_array[10] = new Array("-- Select a person --",
 "Molly Weir 825",
 "Charles (Chic) Murray 891");

option_array[11] = new Array("-- Select a person --",
 "James Matheson 628",
 "David Jacks 1184");

option_array[12] = new Array("-- Select a person --",
 "Sir Arthur Witten Brown 942",
 "Sir John Ross 848");

option_array[13] = new Array("-- Select a person --",
 "James Cox 636",
 "Thomas Coats 502");

option_array[14] = new Array("-- Select a person --",
 "Alexander 'Sawney' Bean 1131",
 "Sir Robert Logan 1326");

option_array[15] = new Array("-- Select a person --",
 "Sir John Leslie 835",
 "Daniel (Dane) Sinclair 1186");

option_array[16] = new Array("-- Select a person --",
 "Sir Robert Spottiswoode 1125",
 "Sir Archibald Primrose 597");

option_array[17] = new Array("-- Select a person --",
 "Andrew Ferguson Neil 673",
 "Carol Smillie 903");

option_array[18] = new Array("-- Select a person --",
 "James Miranda Barry 630",
 "Dr. Joseph Bell 596");

option_array[19] = new Array("-- Select a person --",
 "Sir John Hope 1121",
 "Major General William Roy 730");

option_array[20] = new Array("-- Select a person --",
 "Jane Welsh Carlyle 1141",
 "Gilbert Burns 1191");

option_array[21] = new Array("-- Select a person --",
 "Anthony (Lonnie) Donegan 659",
 "Ronald Belford (Bon) Scott 725");

option_array[22] = new Array("-- Select person --",
 "James Douglas 649",
 "James Duff 729");

option_array[23] = new Array("-- Select a person --",
 "Robert Owen 797",
 "Hope Montagu Douglas Scott 545");

option_array[24] = new Array("-- Select a person --",
 "David Hume 164",
 "Thomas Reid 476");

option_array[25] = new Array("-- Select a person --",
 "Elizabeth (Liz) Lochhead 746",
 "Edwin George Morgan 890");

option_array[26] = new Array("-- Select a person --",
 "Thomas (Tom) Johnston 629",
 "Sir James Hunter Blair 726");

option_array[27] = new Array("-- Select a person --",
 " ");
option_array[28] = new Array("-- Select a person --",
 "James Connolly 756",
 "Lady Francis Balfour 699");

option_array[29] = new Array("-- Select a person --",
 "King Edward II 912",
 "King Edgar 483");

option_array[30] = new Array("-- Select a person --",
 "Charles Lyell 1120",
 "George Forrest 850");
option_array[31] = new Array("-- Select a person --",
 "Annie Lennox 638",
 "Lena Zavaroni 335");

option_array[32] = new Array("-- Select a person --",
 "Martin Martin 375");

option_array[33] = new Array("-- Select Type --",
 "Richard (Dick) McTaggart 1369",
 "Bernard Gallacher 697");



//This is the bit thats gtetting me 

function switch_select()

{
  for (loop = window.document.form_1.KEY1.options.length-1; loop > 0; loop-
-)
  {
    window.document.form_1.KEY1.options[loop] = null;
  }

  for (loop = 0; loop < option_array
[window.document.form_1.select_1.selectedIndex].length; loop++)
  {
    window.document.form_1.KEY1.options[loop] = new Option(option_array
[window.document.form_1.select_1.selectedIndex][loop].substring(0,
(option_array[window.document.form_1.select_1.selectedIndex]
[loop].lastIndexOf(" "))));
    window.document.form_1.KEY1.value[loop] = new Option(option_array
[window.document.form_1.select_1.selectedIndex][loop].substring
((option_array[window.document.form_1.select_1.selectedIndex]
[loop].lastIndexOf(" ")),35));
  }

  window.document.form_1.KEY1.selectedIndex = 0;
}

function set_orig()

{
  window.document.form_1.select_1.selectedIndex = 0;
  window.document.form_1.KEY1.selectedIndex = 0;
}

window.Xnload=set_orig

// -->

</Xcript>

</HEAD>


<TD BGCOLOR="#FFFFCC" VALIGN="TOP" ALIGN="left">
<BLOCKQUOTE><BR>
<FONT COLOR="#000080" FACE="Verdana,Arial,Helvetica,sans-serif">
<H3>Towns associated with Famous people Search</H3><FONT SIZE=-1>
<FORM NAME="form_1" METHOD="POST" 
ACTION="http://www.geo.ed.ac.uk/newXcripts/testsymbol">
<LI>Choose a category to select a famous person.
<P>

<select name="select_1" XnChange="switch_select();">
<option value="1">--- Categories ---</option>
<option value="2">ARTIST</option>
<option value="3">EXPLORER</option>
<option value="4">POLITICIAN</option>
<option value="5">SCIENTIST</option>
<option value="6">REFORMER</option>
<option value="7">ROYALTY</option>
<option value="8">SOCIAL SCIENTIST</option>
<option value="9">INVENTOR</option>
<option value="10">ARCHITECT</option>
<option value="11">AUTHOR</option>
<option value="12">ACADEMIC</option>
<option value="13">POET</option>
<option value="14">ENTREPRENEUR</option>
<option value="15">CLERGY</option>
<option value="16">MUSICIAN</option>
<option value="17">MILITARY</option>
<option value="18">ENGINEER</option>
<option value="19">MEDICAL</option>
<option value="20">CIVIL SERVANT</option>
<option value="21">PHILOSOPHER</option>
<option value="22">PHILANTHROPIST</option>
<option value="23">INDUSTRIALIST</option>
<option value="24">MEDIA PERSONALITY</option>
<option value="25">SPORTS PERSONALITY</option>
<option value="26">ACTOR</option>
<option value="27">MISCELLANEOUS</option>
<option value="28">INFAMOUS</option>
<option value="29">SINGER</option>
<option value="30">COMMERCE</option>
<option value="31">ENTERTAINER</option>
<option value="32">NOBILITY</option>
<option value="33">LAWYER</option>

</select>

  <select name="KEY1">
    <option value="A1">You need to select a category</option>
  </select>

<LI>Once selected the famous person click on the button below to start 
your search.
     <P><INPUT TYPE="SUBMIT" VALUE="Search"></FORM></P>
     </U>
</TD></TR></TABLE></BODY></HTML>

  Return to Index