dynamically populating drop down boxes

Results 1 to 3 of 3

Thread: dynamically populating drop down boxes

  1. #1
    Join Date
    Dec 1969

    Default dynamically populating drop down boxes

    Below is a piece of code that populates one drop down box, based on the selection of another. It works in IE, Netscape 6.2. It will not work in older versions of Netscape or Opera. Any help would be great.<BR><BR>&#060;script type="text/javascript" language="JavaScript"&#062; <BR>function doOp(alist)<BR>{<BR>//************************************************** ******************<BR>//Function fills value dropdown list according to operation value<BR> var Op = &#039;&#039;;<BR> var ndx;<BR> ndx = alist.selectedIndex;<BR> Op =alist.options[ndx].text;<BR> <BR> if (Op == "sum")<BR> {<BR> alist.form.value.options[0].text = "Enr";<BR> alist.form.value.options[1].text = "FTE";<BR> alist.form.value.options[2].text = "Sections";<BR> } <BR> <BR> else if (Op == "Count")<BR> {<BR> alist.form.value.options[0].text = "Dept";<BR> alist.form.value.options[1].text = "Center";<BR> alist.form.value.options[2].text = "Load";<BR> alist.form.value.options[3].text = "Division";<BR> alist.form.value.options[4].text = "Center";<BR> alist.form.value.options[5].test = "Term";<BR> }<BR> else<BR> {<BR> alist.form.value.options[0].text = "Enr";<BR> alist.form.value.options[1].text = "FTE";<BR> alist.form.value.options[2].text = "Sections";<BR> }<BR>}

  2. #2
    Join Date
    Dec 1969

    Default Not sure why...

    I am not sure why Netscape won&#039;t take your code, maybe because you don&#039;t assign a value....<BR><BR>anyhow, I know for certain that this one will, I know because that&#039;s the one we use for our app. (and our app is cross-browser)<BR><BR>/*Note that I&#039;ve been lazy and simply patched around the content of the variables so that I would not have to rename all variables in the code :p*/<BR><BR>var objFrom = document.forms[0].elements[&#039;YourSelectName&#039;]<BR>var objTransfer<BR>var arrFrom = new Array(1)<BR><BR>arrFrom[0] = new Array(1)<BR>arrFrom[1] = new Array(1)<BR><BR>arrFrom[0][0] = "Value1"<BR>arrFrom[0][1] = "Text1"<BR><BR>arrFrom[1][0] = "Value2"<BR>arrFrom[1][1] = "Text2"<BR><BR> //Empty the "From" object<BR> objFrom.options.length = 0<BR> <BR> //Rebuild the "From" object<BR> for (i=0; i &#060; arrFrom.length; i++) {<BR> objTransfer = new Option()<BR> objTransfer.value = arrFrom[i][cVALUE]<BR> objTransfer.text = arrFrom[i][cTEXT]<BR> objFrom.options[objFrom.options.length] = objTransfer<BR> }<BR><BR>Good luck.<BR><BR>Eniac

  3. #3
    Join Date
    Dec 1969

    Default Not even close...

    ...to what NS needs. Or older versions of MSIE, for that matter.<BR><BR>The only reliable way to change the contents of a &#060;SELECT&#062; in NS 4 is to first set all the existing options to null and then rebuild the list using <BR> new Option(...)<BR><BR>See the "Dual Lists in HTML" example on my web page:<BR>http://www.clearviewDesign.com/Newbie<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts