...

View Full Version : Re-populating an empty multiselect...



justincredible
02-21-2007, 04:21 PM
function buildSelect(status){
var xmlhttp=false;
try{// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e){// Internet Explorer
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert('Your browser does not support AJAX!');
return false;
}
}
}
var file = 'chapterAjax.php?chapterStatus=';
xmlHttp.open('GET',file+status,true);
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
for (x = document.getElementById('selectedChapter').length; x >= 0; x--) {
document.getElementById('selectedChapter')[x] = null;
}
var content = xmlHttp.responseText.split(",");
document.getElementById('selectedChapter')[0] = content[377];
for(var i=0;i<content.length;i++){
document.getElementById('selectedChapter')[i] = content[i];
}
document.getElementById('activeChapterBox').disabled = false;
document.getElementById('workingChapterBox').disabled = false;
document.getElementById('nonactiveChapterBox').disabled = false;
document.getElementById('hiddenChapterBox').disabled = false;
document.getElementById('modifiedChapterBox').disabled = false;
}
else{
document.getElementById('activeChapterBox').disabled = true;
document.getElementById('workingChapterBox').disabled = true;
document.getElementById('nonactiveChapterBox').disabled = true;
document.getElementById('hiddenChapterBox').disabled = true;
document.getElementById('modifiedChapterBox').disabled = true;}
}
xmlHttp.send(null);
return;
}

I cannot seem to get the bolded part to do the correct thing.

The for-loop before that is used to completely wipe out my multiselect and I want the bolded code to re-populate that multiselect with the elements that are now in content.

Any ideas?

justincredible
02-21-2007, 07:33 PM
This is the error that I am getting in firebug which means absolutely nothing to me:

[Exception... "Failure" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://myurl.com :: anonymous :: line 1035" data: no]

justincredible
02-21-2007, 11:48 PM
When I alert on content[i] it gives me the right thing so I know it is splitting it correctly.

document.getElementById('selectedChapter')[i] is obviously wrong.

I believe I tried document.getElementById('selectedChapter').option[i] as well but it didn't work either.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum