B
bobsawyer
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.ActiveXObject != 'undefined' ) {
xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
xmlDoc.onreadystatechange = processBrands ;
else {
xmlDoc = new XMLHttpRequest();
xmlDoc.onload = processBrands ;
}
xmlDoc.open( "GET", "getbrands.php?cond="+c, true );
xmlDoc.send( null );
document.foo.condselect.value = c; // inserting the value of c into a
text form element so I can reference it later
document.foo.brandselect.value = 'brands'+d; // inserting 'brands' +
the value of d into a text form element so I can reference it later
}
function processBrands() {
if ( xmlDoc.readyState != 4 ) return ;
delX= "\n";
delY= ",";
valArray = xmlDoc.responseText.split(delX);
d = document.foo.brandselect.value; // getting that first value from
the text element below
document.getElementById(d).options.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.split(delY);
document.getElementById(d).options = new Option(pairArray[1],
pairArray[0]);
}
}
function loadModels(m,z,y) {
if (typeof window.ActiveXObject != 'undefined' ) {
xmlDoc2 = new ActiveXObject("Microsoft.XMLHTTP");
xmlDoc2.onreadystatechange = processModels ;
}
else {
xmlDoc2 = new XMLHttpRequest();
xmlDoc2.onload = processModels ;
}
alert('getmodels.php?model='+m+'&cond='+z);
xmlDoc2.open( "GET", "getmodels.php?model="+m+"&cond="+z, true
);
xmlDoc2.send( null );
document.foo.modelselect.value = 'models'+y;
}
function processModels() {
if ( xmlDoc2.readyState != 4 ) return ;
delX= "\n";
delY= ",";
valArray2 = xmlDoc2.responseText.split(delX);
e = document.foo.modelselect.value;
document.getElementById(e).options.length = 0;
for (var i=0; i <= valArray2.length; i++ ) {
pairArray2 = valArray2.split(delY);
document.getElementById(e).options = new Option(pairArray2[1],
pairArray2[0]);
}
}
</script>
<body>
<form name="foo">
<input type="radio" name="condition1" value="0"
onclick="loadBrands(0,1)" />New
<input type="radio" name="condition1" value="1"
onclick="loadBrands(1,1)" />Used
<select name="brands1" id="brands1"
onchange="loadModels(this.value,document.foo.condselect.value,1);">
<option value="">Select...</option>
</select>
<select name="models1" id="models1">
<option value="">Select...</option>
</select>
<br />
<input type="radio" name="condition2" value="0"
onclick="loadBrands(0,2)" />New
<input type="radio" name="condition2" value="1"
onclick="loadBrands(1,2)" />Used
<select name="brands2" id="brands2"
onchange="loadModels(this.value,document.foo.condselect.value,2);">
<option value="">Select...</option>
</select>
<select name="models2" id="models2">
<option value="">Select...</option>
</select>
<br />
<input type="radio" name="condition3" value="0"
onclick="loadBrands(0,3)" />New
<input type="radio" name="condition3" value="1"
onclick="loadBrands(1,3)" />Used
<select name="brands3" id="brands3"
onchange="loadModels(this.value,document.foo.condselect.value,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="condselect" />
<input type="hidden" id="brandselect" name="brandselect" />
<input type="hidden" id="modelselect" name="modelselect" />
</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.ActiveXObject != 'undefined' ) {
xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
xmlDoc.onreadystatechange = processBrands ;
else {
xmlDoc = new XMLHttpRequest();
xmlDoc.onload = processBrands ;
}
xmlDoc.open( "GET", "getbrands.php?cond="+c, true );
xmlDoc.send( null );
document.foo.condselect.value = c; // inserting the value of c into a
text form element so I can reference it later
document.foo.brandselect.value = 'brands'+d; // inserting 'brands' +
the value of d into a text form element so I can reference it later
}
function processBrands() {
if ( xmlDoc.readyState != 4 ) return ;
delX= "\n";
delY= ",";
valArray = xmlDoc.responseText.split(delX);
d = document.foo.brandselect.value; // getting that first value from
the text element below
document.getElementById(d).options.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.split(delY);
document.getElementById(d).options = new Option(pairArray[1],
pairArray[0]);
}
}
function loadModels(m,z,y) {
if (typeof window.ActiveXObject != 'undefined' ) {
xmlDoc2 = new ActiveXObject("Microsoft.XMLHTTP");
xmlDoc2.onreadystatechange = processModels ;
}
else {
xmlDoc2 = new XMLHttpRequest();
xmlDoc2.onload = processModels ;
}
alert('getmodels.php?model='+m+'&cond='+z);
xmlDoc2.open( "GET", "getmodels.php?model="+m+"&cond="+z, true
);
xmlDoc2.send( null );
document.foo.modelselect.value = 'models'+y;
}
function processModels() {
if ( xmlDoc2.readyState != 4 ) return ;
delX= "\n";
delY= ",";
valArray2 = xmlDoc2.responseText.split(delX);
e = document.foo.modelselect.value;
document.getElementById(e).options.length = 0;
for (var i=0; i <= valArray2.length; i++ ) {
pairArray2 = valArray2.split(delY);
document.getElementById(e).options = new Option(pairArray2[1],
pairArray2[0]);
}
}
</script>
<body>
<form name="foo">
<input type="radio" name="condition1" value="0"
onclick="loadBrands(0,1)" />New
<input type="radio" name="condition1" value="1"
onclick="loadBrands(1,1)" />Used
<select name="brands1" id="brands1"
onchange="loadModels(this.value,document.foo.condselect.value,1);">
<option value="">Select...</option>
</select>
<select name="models1" id="models1">
<option value="">Select...</option>
</select>
<br />
<input type="radio" name="condition2" value="0"
onclick="loadBrands(0,2)" />New
<input type="radio" name="condition2" value="1"
onclick="loadBrands(1,2)" />Used
<select name="brands2" id="brands2"
onchange="loadModels(this.value,document.foo.condselect.value,2);">
<option value="">Select...</option>
</select>
<select name="models2" id="models2">
<option value="">Select...</option>
</select>
<br />
<input type="radio" name="condition3" value="0"
onclick="loadBrands(0,3)" />New
<input type="radio" name="condition3" value="1"
onclick="loadBrands(1,3)" />Used
<select name="brands3" id="brands3"
onchange="loadModels(this.value,document.foo.condselect.value,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="condselect" />
<input type="hidden" id="brandselect" name="brandselect" />
<input type="hidden" id="modelselect" name="modelselect" />
</form>
</body>
</html>
--------------------------------