JavaScript emulation in I.E. is problematic

G

Guest

Hello

I'm creating a 3-stage combo box with JavaScript and HTML. When a user selects one item in the first combo box, it will change the selections available in the next combo box. This code works fine on Mozilla and Netscape, but doesn't quite work right on I.E

Any Suggestions

CODE

<html><head><TITLE>Enter title Here</TITLE><META name="GENERATOR" Content="NeoScript Developer Software Solutions"><META name="DESCRIPTION" Content="Enter Description here"><META name="KEYWORDS" Content="Enter Keywords here"><style type="text/css"><!-
BOD

color:#00FFFF
background-color:black
font-family:sans-serif

A:Link{color:white
A:visited{color:yellow
--></STYLE></head><body><Form name="MMT"><span style="font-family: courier new,courier,monospace;"><fieldset><legend>Select Terminal Combination</legend><p
[Manufacturer.....: ]<Select name="Manuf" size="1" style="width: 50mm" onChange="PopulateModels(manuf_cb.selectedIndex)"></select><p
[Model............: ]<Select name="Model" size="1" style="width: 50mm" onChange="ChangePopulateTerms(manuf_cb.selectedIndex,model_cb.selectedIndex)"></select><p
[Term Application.: ]<Select name="Term" size="1" style="width: 50mm" onChange="ChangeFindMaxTrack(manuf_cb.selectedIndex,model_cb.selectedIndex,term_cb.selectedIndex)"></select><p
[Track............: ]<Select name="Track" size="1" style="width: 50mm" disabled="true"></select><p><Input type=Submit value="New Insert Record" name=insert style="width: 50mm"><Input type=Submit value="New Update Record" name=update style="width: 50mm"></fieldset></span><br style="font-family: courier new,courier,monospace;"><!-- Insert HTML here --><script language=JavaScript

var manuf_ct =
var manuf_arr = new Array(manuf_ct
manuf_arr[0]="VERIFONE
manuf_arr[1]="COMPUTER
manuf_arr[2]="THALES
manuf_arr[3]="HYPERCOM
manuf_arr[4]="CHECKSVS
manuf_arr[5]="BAOHX
manuf_arr[6]="BATCH
var model_ct = 2
var model_arr = new Array(model_ct
model_arr[0]="TRANZ 330
model_arr[1]="OMNI 395
model_arr[2]="ZON JR XL
model_arr[3]="XL300
model_arr[4]="OMNI 396
model_arr[5]="TRANZ 380
model_arr[6]="OMNI 470
model_arr[7]="OMNI 3200
model_arr[8]="PC
model_arr[9]="TRANZ 460
model_arr[10]="OMNI 3210
model_arr[11]="T-ONE
model_arr[12]="T-IPP
model_arr[13]="T-IPPS
model_arr[14]="T7E
model_arr[15]="T7P
model_arr[16]="T77
model_arr[17]="T8
model_arr[18]="CCS
model_arr[19]="POS
model_arr[20]="AUTH
model_arr[21]="ICE 5000
model_arr[22]="ICE 5500
model_arr[23]="ICE 5500P
var term_ct = 4
var term_arr = new Array(term_ct
term_arr[0]="VSTDB01
term_arr[1]="VSVR035
term_arr[2]="VXL0P32
term_arr[3]="VXP0P16
term_arr[4]="VT1TP04
term_arr[5]="VT1TPA4
term_arr[6]="VT13DA4
term_arr[7]="VT13DA6
term_arr[8]="VT1TP05
term_arr[9]="VT13PA3
term_arr[10]="VT1CD02
term_arr[11]="VXPCD02
term_arr[12]="VT1H384
term_arr[13]="VT13DA7
term_arr[14]="VT13DA8
term_arr[15]="VT1DB01
term_arr[16]="VT1TP08
term_arr[17]="VT1TPA6
term_arr[18]="VT1TPA7
term_arr[19]="VT1TP07
term_arr[20]="PP2K
term_arr[21]="VT1H385
term_arr[22]="VT46DA4
term_arr[23]="VT1TPH6
term_arr[24]="VSVR046
term_arr[25]="VT1TPH5
term_arr[26]="VT46DA1
term_arr[27]="VT1TP06
term_arr[28]="VT46DA3
term_arr[29]="52C8072
term_arr[30]="PP2K-M
term_arr[31]="DHTL
term_arr[32]="TELECRE
term_arr[33]="OHXHC
term_arr[34]="BACS
term_arr[35]="DICERR
term_arr[36]="DRR
term_arr[37]="VSVR022
term_arr[38]="HTL
term_arr[39]="FD
term_arr[40]="ICERR
term_arr[41]="RR
var matrix_ct = 13
var matrix_arr = new Array(matrix_ct
matrix_arr[0]="00_00_00_2
matrix_arr[1]="00_01_01_1
matrix_arr[2]="00_01_01_2
matrix_arr[3]="00_02_02_2
matrix_arr[4]="00_03_02_2
matrix_arr[5]="00_02_03_2
matrix_arr[6]="00_03_03_2
matrix_arr[7]="00_00_04_2
matrix_arr[8]="00_00_04_1
matrix_arr[9]="00_00_05_2
matrix_arr[10]="00_00_05_1
matrix_arr[11]="00_04_01_1
matrix_arr[12]="00_04_01_2
matrix_arr[13]="00_05_06_2"
matrix_arr[14]="00_05_06_1"
matrix_arr[15]="00_05_07_2"
matrix_arr[16]="00_05_07_1"
matrix_arr[17]="00_06_01_1"
matrix_arr[18]="00_06_01_2"
matrix_arr[19]="00_00_08_2"
matrix_arr[20]="00_00_08_1"
matrix_arr[21]="00_05_09_2"
matrix_arr[22]="00_05_09_1"
matrix_arr[23]="00_00_10_2"
matrix_arr[24]="00_00_10_1"
matrix_arr[25]="00_02_11_2"
matrix_arr[26]="00_03_11_2"
matrix_arr[27]="00_05_12_2"
matrix_arr[28]="00_05_12_1"
matrix_arr[29]="00_07_01_1"
matrix_arr[30]="00_07_01_2"
matrix_arr[31]="00_05_13_1"
matrix_arr[32]="00_05_13_2"
matrix_arr[33]="00_05_14_1"
matrix_arr[34]="00_05_14_2"
matrix_arr[35]="00_00_15_1"
matrix_arr[36]="00_00_16_1"
matrix_arr[37]="00_00_16_2"
matrix_arr[38]="00_00_17_2"
matrix_arr[39]="00_00_17_1"
matrix_arr[40]="00_00_18_2"
matrix_arr[41]="00_00_19_2"
matrix_arr[42]="00_00_19_1"
matrix_arr[43]="01_08_20_1"
matrix_arr[44]="01_08_20_2"
matrix_arr[45]="00_05_21_1"
matrix_arr[46]="00_05_21_2"
matrix_arr[47]="00_09_22_1"
matrix_arr[48]="00_09_22_2"
matrix_arr[49]="00_00_18_1"
matrix_arr[50]="00_00_23_1"
matrix_arr[51]="00_00_23_2"
matrix_arr[52]="00_01_24_1"
matrix_arr[53]="00_00_25_2"
matrix_arr[54]="00_00_25_1"
matrix_arr[55]="00_09_26_2"
matrix_arr[56]="00_09_26_1"
matrix_arr[57]="00_00_27_2"
matrix_arr[58]="00_00_27_1"
matrix_arr[59]="00_01_24_2"
matrix_arr[60]="00_04_24_1"
matrix_arr[61]="00_09_28_2"
matrix_arr[62]="00_09_28_1"
matrix_arr[63]="00_04_24_2"
matrix_arr[64]="00_06_24_1"
matrix_arr[65]="00_06_24_2"
matrix_arr[66]="00_07_24_1"
matrix_arr[67]="00_07_24_2"
matrix_arr[68]="00_10_24_1"
matrix_arr[69]="00_10_24_2"
matrix_arr[70]="02_11_29_2"
matrix_arr[71]="02_12_29_2"
matrix_arr[72]="02_13_29_2"
matrix_arr[73]="01_08_30_1"
matrix_arr[74]="01_08_30_2"
matrix_arr[75]="03_14_31_1"
matrix_arr[76]="03_14_31_2"
matrix_arr[77]="03_15_31_1"
matrix_arr[78]="03_15_31_2"
matrix_arr[79]="03_16_31_1"
matrix_arr[80]="03_16_31_2"
matrix_arr[81]="03_17_31_1"
matrix_arr[82]="03_17_31_2"
matrix_arr[83]="04_18_32_2"
matrix_arr[84]="04_18_32_1"
matrix_arr[85]="05_19_33_1"
matrix_arr[86]="05_19_33_2"
matrix_arr[87]="06_20_34_1"
matrix_arr[88]="03_21_35_1"
matrix_arr[89]="03_21_35_2"
matrix_arr[90]="03_22_35_1"
matrix_arr[91]="03_22_35_2"
matrix_arr[92]="03_23_35_1"
matrix_arr[93]="03_23_35_2"
matrix_arr[94]="03_14_36_1"
matrix_arr[95]="03_14_36_2"
matrix_arr[96]="03_15_36_1"
matrix_arr[97]="03_15_36_2"
matrix_arr[98]="03_16_36_1"
matrix_arr[99]="03_16_36_2"
matrix_arr[100]="03_17_36_1"
matrix_arr[101]="03_17_36_2"
matrix_arr[102]="00_01_37_1"
matrix_arr[103]="00_01_37_2"
matrix_arr[104]="00_04_37_1"
matrix_arr[105]="00_04_37_2"
matrix_arr[106]="00_06_37_1"
matrix_arr[107]="00_06_37_2"
matrix_arr[108]="00_07_37_1"
matrix_arr[109]="00_07_37_2"
matrix_arr[110]="03_14_38_1"
matrix_arr[111]="03_14_38_2"
matrix_arr[112]="03_15_38_1"
matrix_arr[113]="03_15_38_2"
matrix_arr[114]="03_16_38_1"
matrix_arr[115]="03_16_38_2"
matrix_arr[116]="03_17_38_1"
matrix_arr[117]="03_17_38_2"
matrix_arr[118]="03_14_39_1"
matrix_arr[119]="03_14_39_2"
matrix_arr[120]="03_15_39_1"
matrix_arr[121]="03_15_39_2"
matrix_arr[122]="03_16_39_1"
matrix_arr[123]="03_16_39_2"
matrix_arr[124]="03_21_40_1"
matrix_arr[125]="03_21_40_2"
matrix_arr[126]="03_22_40_1"
matrix_arr[127]="03_22_40_2"
matrix_arr[128]="03_23_40_1"
matrix_arr[129]="03_23_40_2"
matrix_arr[130]="03_14_41_1"
matrix_arr[131]="03_14_41_2"
matrix_arr[132]="03_15_41_1"
matrix_arr[133]="03_15_41_2"
matrix_arr[134]="03_16_41_1"
matrix_arr[135]="03_16_41_2"
matrix_arr[136]="03_17_41_1"
matrix_arr[137]="03_17_41_2"

var manuf_cb = document.MMT.Manuf
var model_cb = document.MMT.Model
var term_cb = document.MMT.Term
var track_cb = document.MMT.Track

var e_manuf = " "
var e_model = " "
var e_term = " "
var e_track = " "

var e_max_track = 0

PopulateManufacturers()
// document.write("2 DIGIT MANUF: "+c1+" MODEL: "+e_model+"<BR>")

function FindMaxTrack(manuf_idx,model_idx,term_idx) {
// Loop through matrix and string match
e_max_track =0
for (i=0;i<matrix_ct;i++) {
BreakMatrixLineDown(matrix_arr) // Break the matrix down
if (manuf_idx == e_manuf) // Match Manufactuer ?
if (model_idx == e_model) // Models match ?
if (term_idx == e_term) // Term Matches?
if (e_track > e_max_track)
e_max_track = e_track
}

// Clear out old Options if it exists (out with the old)
for(i = track_cb.options.length-1; i>=0; i--)
track_cb.options=null

track_cb.options[0] = new Option(e_max_track,0)
}

function BreakMatrixLineDown(matrix_line) {
if (matrix_line[0] != 0)
e_manuf = matrix_line[0]+matrix_line[1]
else
e_manuf = matrix_line[1]

if (matrix_line[3] != 0)
e_model = matrix_line[3]+matrix_line[4]
else
e_model = matrix_line[4]

if (matrix_line[6] != 0)
e_term = matrix_line[6]+matrix_line[7]
else
e_term = matrix_line[7]

e_track = matrix_line[9]
}

function PopulateTerms(manuf_idx,model_idx) {

//document.write("Populating Terms: "+manuf_arr[manuf_idx]+" "+model_arr[model_idx]+"<BR>")

var ct = 0
var first = -1

// Clear out old Options if it exists (out with the old)
for(i = term_cb.options.length-1; i>=0; i--)
term_cb.options=null

// Loop through matrix and string match
for (i=0;i<matrix_ct;i++) {
BreakMatrixLineDown(matrix_arr) // Break the matrix down
if (manuf_idx == e_manuf) { // Match Manufactuer ?
if (model_idx == e_model) { // Models match ?

var already_added = false
var temp_term = term_arr[e_term]
// document.write(manuf_arr[manuf_idx]+" "+model_arr[model_idx]+" "+temp_term+"<BR>")
for(ii = 0; ii< term_cb.options.length; ii++)
if ( term_cb.options[ii].text == temp_term)
already_added=true

if (false == already_added) {
if (first == -1)
first = e_term
term_cb.options[ct] = new Option(temp_term,e_term)
ct++
}
}
}
}
term_cb.options[0].selected=true
FindMaxTrack(manuf_idx,model_idx,first)
}



function PopulateModels(manuf_idx) {

var first=-1

// Clear out old Options if it exists (out with the old)
for(i = model_cb.options.length-1; i>=0; i--)
model_cb.options=null

var ct = 0

// Loop through matrix an string match
for (i=0;i<matrix_ct;i++) {
BreakMatrixLineDown(matrix_arr)
if (manuf_idx == e_manuf) {
var already_added = false
var temp_model = model_arr[e_model]

for(ii = 0; ii< model_cb.options.length; ii++)
if ( model_cb.options[ii].text == temp_model)
already_added=true

if (false == already_added) {
if (first == -1)
first = e_model;
model_cb.options[ct] = new Option(temp_model,e_model)
ct++

}
}
}
model_cb.options[0].selected=true;
PopulateTerms(manuf_idx,first)
}

function PopulateManufacturers() {
// Clear out old Options if it exists (out with the old)
for(i = manuf_cb.options.length-1; i>=0; i--)
manuf_cb.options=null

// Add new Options (in with the new!)
for (i=0; i< manuf_ct; i++)
manuf_cb.options = new Option(manuf_arr,i)

manuf_cb.options[0].selected=true
PopulateModels(0)
}

// The combo boxes have a different indexing scheme
// than our matrix does, so we have to remap the selected
// indexes in the combo box and normalize them with the
// matrix combo boxes

function ChangePopulateTerms(manuf_cb_idx, model_cb_idx) {
manuf_idx = manuf_cb_idx
model_idx = model_cb.options[model_cb_idx].value
PopulateTerms(manuf_idx,model_idx)
}

function ChangeFindMaxTrac(manuf_cb_idx,model_cb_idx,term_cb_idx) {
manuf_idx = manuf_cb_idx
model_idx = model_cb.options[model_cb_idx].value
term_idx = term_cb.options[term_cb_idx].value
FindMaxTrac(manuf_idx,model_idx,term_idx)
}

</script></form></body></html>
 
G

Guest

Hi All

I found the fix. I've traced the problem down to a JavaScript stupidity, and a Internet Explorer weakness/strength depending on how you see it. It seems as if Mozilla's and Netscape are a little more "Intelligent" in knowing if a variable should be treated like a string or an integer.

The fix for the code posted before is to replace this section of code

function BreakMatrixLineDown(matrix_line)
if (matrix_line.charAt(0) != "0")
e_manuf = matrix_line.charAt(0)+matrix_line.charAt(1)
els
e_manuf = matrix_line.charAt(0)

if (matrix_line.charAt(3) != "0"
e_model = matrix_line.charAt(3)+matrix_line.charAt(4)
else
e_model = matrix_line.charAt(4)

if (matrix_line.charAt(6) != "0"
e_term = matrix_line.charAt(6)+matrix_line.charAt(7)
els
e_term = matrix_line.charAt(7)

e_track = matrix_line.charAt(9)
}


The problem was when I was dereferencing the matrix_line and adding them together. matrix_line[0]+matrix_line[1] Depending on your school of thought, that is either a numeric addition, or it's a string concatination. Since the var in javascript is lame in that it doesn't differenciate betwen int and string or char, then it's up to the javascript emulator to. In this case, it appears as if IE decided to treat it like an integer (or something funky) and return NaN whereas Mozilla and Netscape knew to treat it as a string and just concatinate the values

I got around the snagg by forcing it to .charAt(0)+.charAt(1) so that there was no mistake about treating it like a string concatination

Hope this helps you in your Scripting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top