I've been building a series of SELECT lists that are populated
dynamically using HTTPRequest. Things are going pretty well, and I've
got the whole thing working flawlessly in Mozilla/Firebird.
Unfortunately, Internet Explorer doesn't quite work as expected -- it
gives me an "invalid argument" error that I don't know how to fix.
Here's the entire script, with form, annotated to explain what I'm
doing and where the problem is occurring. I would link the URL where
the form resides on the server, but cannot due to security concerns.
Thing is, I just don't know what to do to fix it. In a nutshell, when
you click on the first set of radio buttons, nothing happens. If you
click again, it then populates the first SELECT list in the first row.
It SHOULD populate the list on the first click. Additionally, if you
skip the first row and go to the second, and click a radio button, it
populates the SELECT in the FIRST row, rather than the second.
If anyone can assist me with this I would be really grateful. I've
managed to piece this together today despite not really knowing much
about Javascript, but I've hit the wall with this error. Thanks!
-Bob
-------------------------
<html>
<script>
var xmlDoc = null ;
var c = '';
var d = '';
var o = '';
var m = '';
var z = '';
var y = '';
function loadBrands(c,d) {
if (typeof window.ActiveXO bject != 'undefined' ) {
xmlDoc = new ActiveXObject(" Microsoft.XMLHT TP");
xmlDoc.onreadys tatechange = processBrands ;
else {
xmlDoc = new XMLHttpRequest( );
xmlDoc.onload = processBrands ;
}
xmlDoc.open( "GET", "getbrands.php? cond="+c, true );
xmlDoc.send( null );
document.foo.co ndselect.value = c; // inserting the value of c into a
text form element so I can reference it later
document.foo.br andselect.value = 'brands'+d; // inserting 'brands' +
the value of d into a text form element so I can reference it later
}
function processBrands() {
if ( xmlDoc.readySta te != 4 ) return ;
delX= "\n";
delY= ",";
valArray = xmlDoc.response Text.split(delX );
d = document.foo.br andselect.value ; // getting that first value from
the text element below
document.getEle mentById(d).opt ions.length = 0; // this
is where IE tells me the error is occurring, at the 'getElementById (d)'
position
for (var i=0; i <= valArray.length ; i++ ) {
pairArray = valArray[i].split(delY);
document.getEle mentById(d).opt ions[i] = new Option(pairArra y[1],
pairArray[0]);
}
}
function loadModels(m,z, y) {
if (typeof window.ActiveXO bject != 'undefined' ) {
xmlDoc2 = new ActiveXObject(" Microsoft.XMLHT TP");
xmlDoc2.onready statechange = processModels ;
}
else {
xmlDoc2 = new XMLHttpRequest( );
xmlDoc2.onload = processModels ;
}
alert('getmodel s.php?model='+m +'&cond='+z);
xmlDoc2.open( "GET", "getmodels.php? model="+m+"&con d="+z, true
);
xmlDoc2.send( null );
document.foo.mo delselect.value = 'models'+y;
}
function processModels() {
if ( xmlDoc2.readySt ate != 4 ) return ;
delX= "\n";
delY= ",";
valArray2 = xmlDoc2.respons eText.split(del X);
e = document.foo.mo delselect.value ;
document.getEle mentById(e).opt ions.length = 0;
for (var i=0; i <= valArray2.lengt h; i++ ) {
pairArray2 = valArray2[i].split(delY);
document.getEle mentById(e).opt ions[i] = new Option(pairArra y2[1],
pairArray2[0]);
}
}
</script>
<body>
<form name="foo">
<input type="radio" name="condition 1" value="0"
onclick="loadBr ands(0,1)" />New
<input type="radio" name="condition 1" value="1"
onclick="loadBr ands(1,1)" />Used
<select name="brands1" id="brands1"
onchange="loadM odels(this.valu e,document.foo. condselect.valu e,1);">
<option value="">Select ...</option>
</select>
<select name="models1" id="models1">
<option value="">Select ...</option>
</select>
<br />
<input type="radio" name="condition 2" value="0"
onclick="loadBr ands(0,2)" />New
<input type="radio" name="condition 2" value="1"
onclick="loadBr ands(1,2)" />Used
<select name="brands2" id="brands2"
onchange="loadM odels(this.valu e,document.foo. condselect.valu e,2);">
<option value="">Select ...</option>
</select>
<select name="models2" id="models2">
<option value="">Select ...</option>
</select>
<br />
<input type="radio" name="condition 3" value="0"
onclick="loadBr ands(0,3)" />New
<input type="radio" name="condition 3" value="1"
onclick="loadBr ands(1,3)" />Used
<select name="brands3" id="brands3"
onchange="loadM odels(this.valu e,document.foo. condselect.valu e,3);">
<option value="">Select ...</option>
</select>
<select name="models3" id="models3">
<option value="">Select ...</option>
</select>
<br />
<!-- these hidden fields are used to hold values generated by the
functions in the script at the top of the page -->
<input type="hidden" id="condselect " name="condselec t" />
<input type="hidden" id="brandselect " name="brandsele ct" />
<input type="hidden" id="modelselect " name="modelsele ct" />
</form>
</body>
</html>
--------------------------------
dynamically using HTTPRequest. Things are going pretty well, and I've
got the whole thing working flawlessly in Mozilla/Firebird.
Unfortunately, Internet Explorer doesn't quite work as expected -- it
gives me an "invalid argument" error that I don't know how to fix.
Here's the entire script, with form, annotated to explain what I'm
doing and where the problem is occurring. I would link the URL where
the form resides on the server, but cannot due to security concerns.
Thing is, I just don't know what to do to fix it. In a nutshell, when
you click on the first set of radio buttons, nothing happens. If you
click again, it then populates the first SELECT list in the first row.
It SHOULD populate the list on the first click. Additionally, if you
skip the first row and go to the second, and click a radio button, it
populates the SELECT in the FIRST row, rather than the second.
If anyone can assist me with this I would be really grateful. I've
managed to piece this together today despite not really knowing much
about Javascript, but I've hit the wall with this error. Thanks!
-Bob
-------------------------
<html>
<script>
var xmlDoc = null ;
var c = '';
var d = '';
var o = '';
var m = '';
var z = '';
var y = '';
function loadBrands(c,d) {
if (typeof window.ActiveXO bject != 'undefined' ) {
xmlDoc = new ActiveXObject(" Microsoft.XMLHT TP");
xmlDoc.onreadys tatechange = processBrands ;
else {
xmlDoc = new XMLHttpRequest( );
xmlDoc.onload = processBrands ;
}
xmlDoc.open( "GET", "getbrands.php? cond="+c, true );
xmlDoc.send( null );
document.foo.co ndselect.value = c; // inserting the value of c into a
text form element so I can reference it later
document.foo.br andselect.value = 'brands'+d; // inserting 'brands' +
the value of d into a text form element so I can reference it later
}
function processBrands() {
if ( xmlDoc.readySta te != 4 ) return ;
delX= "\n";
delY= ",";
valArray = xmlDoc.response Text.split(delX );
d = document.foo.br andselect.value ; // getting that first value from
the text element below
document.getEle mentById(d).opt ions.length = 0; // this
is where IE tells me the error is occurring, at the 'getElementById (d)'
position
for (var i=0; i <= valArray.length ; i++ ) {
pairArray = valArray[i].split(delY);
document.getEle mentById(d).opt ions[i] = new Option(pairArra y[1],
pairArray[0]);
}
}
function loadModels(m,z, y) {
if (typeof window.ActiveXO bject != 'undefined' ) {
xmlDoc2 = new ActiveXObject(" Microsoft.XMLHT TP");
xmlDoc2.onready statechange = processModels ;
}
else {
xmlDoc2 = new XMLHttpRequest( );
xmlDoc2.onload = processModels ;
}
alert('getmodel s.php?model='+m +'&cond='+z);
xmlDoc2.open( "GET", "getmodels.php? model="+m+"&con d="+z, true
);
xmlDoc2.send( null );
document.foo.mo delselect.value = 'models'+y;
}
function processModels() {
if ( xmlDoc2.readySt ate != 4 ) return ;
delX= "\n";
delY= ",";
valArray2 = xmlDoc2.respons eText.split(del X);
e = document.foo.mo delselect.value ;
document.getEle mentById(e).opt ions.length = 0;
for (var i=0; i <= valArray2.lengt h; i++ ) {
pairArray2 = valArray2[i].split(delY);
document.getEle mentById(e).opt ions[i] = new Option(pairArra y2[1],
pairArray2[0]);
}
}
</script>
<body>
<form name="foo">
<input type="radio" name="condition 1" value="0"
onclick="loadBr ands(0,1)" />New
<input type="radio" name="condition 1" value="1"
onclick="loadBr ands(1,1)" />Used
<select name="brands1" id="brands1"
onchange="loadM odels(this.valu e,document.foo. condselect.valu e,1);">
<option value="">Select ...</option>
</select>
<select name="models1" id="models1">
<option value="">Select ...</option>
</select>
<br />
<input type="radio" name="condition 2" value="0"
onclick="loadBr ands(0,2)" />New
<input type="radio" name="condition 2" value="1"
onclick="loadBr ands(1,2)" />Used
<select name="brands2" id="brands2"
onchange="loadM odels(this.valu e,document.foo. condselect.valu e,2);">
<option value="">Select ...</option>
</select>
<select name="models2" id="models2">
<option value="">Select ...</option>
</select>
<br />
<input type="radio" name="condition 3" value="0"
onclick="loadBr ands(0,3)" />New
<input type="radio" name="condition 3" value="1"
onclick="loadBr ands(1,3)" />Used
<select name="brands3" id="brands3"
onchange="loadM odels(this.valu e,document.foo. condselect.valu e,3);">
<option value="">Select ...</option>
</select>
<select name="models3" id="models3">
<option value="">Select ...</option>
</select>
<br />
<!-- these hidden fields are used to hold values generated by the
functions in the script at the top of the page -->
<input type="hidden" id="condselect " name="condselec t" />
<input type="hidden" id="brandselect " name="brandsele ct" />
<input type="hidden" id="modelselect " name="modelsele ct" />
</form>
</body>
</html>
--------------------------------
Comment