PDA

View Full Version : Resetting a combo box with NN4.7


Running Bear
09-11-2002, 02:23 PM
I'm trying to reset a combo box in Netscape 4.7.
can anyone see where I'm going wrong?




<script language="javascript">

// Populate the var which will hold what control in the form to populate
var myCtlID='<%=dynAID%>';


if(ns4){
document.layers[myCtlID].options.length = 0;
}

</script>


Thanks

Al

dreamingdigital
09-11-2002, 03:34 PM
try this

<script language="javascript">

var myCtlID='<%=dynAID%>';
var i=0; //replace 0 with the actual numeric order number of the <select option> you want to access

if(ns4){
document.layers[myCtlID].document.theformyouareusingsname.options[i].length = 0;
}

</script>

Running Bear
09-11-2002, 03:44 PM
DreamingDigital,

Thanks for your reply but I still can't get it to work!?

piglet
09-11-2002, 04:08 PM
Hi Running Bear


It's near impossible to help on this sort of question without seeing the code - do you have a URL, or a cut-down page you can show?

requestcode
09-11-2002, 04:11 PM
For NS4 version browsers if you are changing a combo box then you need to refresh the page after the change is done. I usually use history.go(0). Then you will see the change made.

Running Bear
09-11-2002, 04:24 PM
Thanks for all your interest here is a cut down version of the page. This code works fine in IE 5.5 + and NS6.1+



<html>
<body>
<SCRIPT language="JavaScript">
<!-- // Begin Hide

/*
Browser sniffer. Written by PerlScriptsJavaScripts.com
*/

v3 = 0; op = 0; ie4 = 0; ie5 = 0; nn4 = 0; nn6 = 0; isMac = 0; aol = 0;

if(document.images){
if(navigator.userAgent.indexOf("Opera") != -1){
op = 1;
} else {
if(navigator.userAgent.indexOf("AOL") != -1){
aol = 1;
} else {
ie4 = (document.all && !document.getElementById);
nn4 = (document.layers);
ie5 = (document.all && document.getElementById);
nn6 = (document.addEventListener);
}
}
} else {
v3 = 1;
}

if(navigator.userAgent.indexOf("Mac") != -1){
isMac = 1;
}


// A multi-dimensional array to hold all the divisions and their associated Contingency Plans
// using javascript with embeded server side VBScript
var a = new Array(); //main table recordcount

a[1] = new Array(); // number of linked items in table 2 by record in main table
a[2] = new Array(); // number of linked items in table 2 by record in main table

a[2][0] = new Array(2); // always 2
a[2][0][0] = "Power Supplies" // option text
a[2][0][1] = "25" // primary key

a[2][1] = new Array(2); // always 2
a[2][1][0] = "Security" // option text
a[2][1][1] = "26" // primary key

a[3] = new Array(); // number of linked items in table 2 by record in main table
a[4] = new Array(); // number of linked items in table 2 by record in main table
a[5] = new Array(); // number of linked items in table 2 by record in main table
a[6] = new Array(); // number of linked items in table 2 by record in main table


// Populate the var which will hold what control in the form to populate
var myCtlID='KBPID_n';

function doselect(index) {
var ns4 = (document.layers);

alert("I'm changing")

if(nn4){ // do this
alert("Ist Netscape 4 alert");
document.layers[myCtlID].options.length = 0;
history.go(0)
}else{

document.getElementById(myCtlID).options.length = 0;
}

if (index != 0) {
var k = 0; // Option index

if(nn4){ // do this
alert("Netscape 4")


}else {
// Make the first Item in the combo 'Select'
var new1stOpt = new Option("[Select]")
document.getElementById(myCtlID).options[k] = new1stOpt
document.getElementById(myCtlID).options[k].value = 0

// Add the new values to display
for (var i=0;i<a[index].length;i++) {
k++ // Increment the option index
var newOption = new Option(a[index][i][0])
document.getElementById(myCtlID).options[k] = newOption
document.getElementById(myCtlID).options[k].value = a[index][i][1]
}
}
}
}

// End Hide -->
</script>


<table cellpadding="0" cellspacing="0" border="0" bgcolor="#FFFFFF" align=center width="685">
<tr>
<td bgcolor='#CFD9FF' colspan=2 width='715'><b>Edit</b></td>
</tr>
<form action="" AUTOCOMPLETE="off" method="" id=myform name=myform onSubmit="">
<tr>
<td bgcolor="#C0C0FF" colspan="2" width="715"><b>&nbsp;</b></td>
</tr>
<tr>
<td align=right bgcolor="#F7F7F7" width="250"><b>Division Name: </b></td>
<td bgcolor="#F7F7F7" width="400">
<Select Name="iDivID_z" id="iDivID_z" size="1" onchange="doselect(this.selectedIndex);" style="WIDTH:200">
<Option Value ="">[Select]</Option>
<Option Value="3">Operations</Option>
<Option Value="4"Selected>Wholesale Marketing</Option>
<Option Value="7">Network Access</Option>
<Option Value="8">Network Transport</Option>
<Option Value="9">Network Build</Option>
<Option Value="10">Finance</Option>
</select></td>
</tr>
<tr>
<td align=right bgcolor="#F7F7F7" width="250"><b>KBP Name: </b></td>
<td bgcolor="#F7F7F7" width="400">
<Select Name="KBPID_n" id="KBPID_n" size="1" style="WIDTH:240">
<Option Value ="">[Select]</Option>
<Option Value ="25 " Selected> Power Supplies</Option>
<Option Value ="26 " > Security</Option>
</select></td>
</tr>
<tr>
<td align=right bgcolor="#F7F7F7" width="250"><b>Risk Name: </b></td>
<td bgcolor="#F7F7F7" width="400">
<select onchange="popRiskText();" name=cboRisks_z id=cboRisks_z>
<option value="Other (Please Specify)">Other (Please Specify)</option>
<option value='Lightening Strike'>Lightening Strike</option>
</select></td>
</tr>
</table>
</BODY>
</HTML>