bbrantley
06-16-2008, 03:50 PM
I'm writing a simple page using XMLHTTPRequest to a CGI file on a server that spits out a data set when executed. The data set is formatted as follows:
name,value,name,value,name,value...
Once I receive the data I run the set through the following code to update any part of the website that has changed.
var mytext = http.responseText.split(",");
for (var i = 0; i < mytext.length; i = i + 2) {
document.getElementById(mytext[i]).innerHTML = mytext[i + 1];
}
This works fine as long as the 'name' portion has <div id='name'> associated with it. For example, if the data set is:
3,100,4,200
and there isn't a div id equal to 3, it hangs the program up. My page won't always have the same div id's, but could possibly receive a name in the data set that addresses a div id that is missing. Is there any kind of try/catch code associated with writing the innerHTML of a div?
Thank you for your time.
name,value,name,value,name,value...
Once I receive the data I run the set through the following code to update any part of the website that has changed.
var mytext = http.responseText.split(",");
for (var i = 0; i < mytext.length; i = i + 2) {
document.getElementById(mytext[i]).innerHTML = mytext[i + 1];
}
This works fine as long as the 'name' portion has <div id='name'> associated with it. For example, if the data set is:
3,100,4,200
and there isn't a div id equal to 3, it hangs the program up. My page won't always have the same div id's, but could possibly receive a name in the data set that addresses a div id that is missing. Is there any kind of try/catch code associated with writing the innerHTML of a div?
Thank you for your time.