johnb.
08-14-2007, 10:47 PM
hey all-
this is my first post in here, so hello to you all and thanks for taking the time to check out what i've to say.
this is also my first time to use javascript in any real capacity in a project. here's the background: i'm helping a client weed out some issues they've been having with some of their services, the way we're going about it is by having a record of all the employees and some info about them in an xml file, then having the feature of searching by name, check amount, and check id number. the hope is to eliminate some counterfeit checks that have been made lately.
so, i've got the javascript parsing the xml and writing it to the screen, but the search feature (which is in the html) is then gone because the document.write() function.
i had tried using getElementById('divName').innerHTML to fill in the screen with the parsed data, but it never showed up on screen, although it did in fact look to be working correctly when i had an alert show what was being written in the innerHTML.
here's the current code:
<script type="text/javascript">
var xmlDoc;
function loadXML(){
//load xml file
// code for IE
if (window.ActiveXObject){
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("payroll.xml");
setupXML();
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument){
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load("payroll.xml");
xmlDoc.async=false;
xmlDoc.onload = setupXML;
}else{
alert('Your browser cannot handle this script');
}
}
function setupXML(){
//set variables to equal the right data
employees = xmlDoc.getElementsByTagName('employee');
employeeFirst = xmlDoc.getElementsByTagName('first');
employeeLast = xmlDoc.getElementsByTagName('last');
checkId = xmlDoc.getElementsByTagName('checkId');
checkAmt = xmlDoc.getElementsByTagName('checkAmt');
//
//run through the XML file, grab the data in the various
//arrays and then throw it down in the HTML after creating space for it
//
//write the html to put junk in there
//
var firstHalfDiv = "<table> \n <tr> \n <div id='DivWrapsHolder'>\n";
var lastHalfDiv = "</div> \n </tr> \n </table> \n";
document.write(firstHalfDiv);
for(i=0;i<employees.length;i++){
//
//populate the newly created table cells
//
document.write("<div id='DivWrapper_"+i+"' style='font-family:Arial, Helvetica, sans-serif;'>");
document.write("<table> \n\n");
document.write("<tr> \n");
document.write("<td id='FirstName_"+i+"'> \n <p>"+employeeFirst[i].firstChild.nodeValue+"</p>\n");
document.write("</td> \n");
document.write("<td id='LastName_"+i+"'> \n <p>"+employeeLast[i].firstChild.nodeValue+"</p>\n");
document.write("</td> \n");
document.write("<td id='CheckAmt_"+i+"'> \n <p>"+checkAmt[i].firstChild.nodeValue+"</p>\n");
document.write("</td> \n");
document.write("<td id='CheckId_"+i+"'> \n <p>"+checkId[i].firstChild.nodeValue+"</p>\n");
document.write("</td> \n");
document.write("</tr> \n");
document.write("</table> \n\n");
document.write("</div> \n\n");
}
document.write(lastHalfDiv);
}
</script>
also, the page never totally loads after it writes those xml values, it just seems stuck. i'm not sure if it's because i've incorrectly tried to implement the asynchronous part of things or not.
thanks for any help!!
john
this is my first post in here, so hello to you all and thanks for taking the time to check out what i've to say.
this is also my first time to use javascript in any real capacity in a project. here's the background: i'm helping a client weed out some issues they've been having with some of their services, the way we're going about it is by having a record of all the employees and some info about them in an xml file, then having the feature of searching by name, check amount, and check id number. the hope is to eliminate some counterfeit checks that have been made lately.
so, i've got the javascript parsing the xml and writing it to the screen, but the search feature (which is in the html) is then gone because the document.write() function.
i had tried using getElementById('divName').innerHTML to fill in the screen with the parsed data, but it never showed up on screen, although it did in fact look to be working correctly when i had an alert show what was being written in the innerHTML.
here's the current code:
<script type="text/javascript">
var xmlDoc;
function loadXML(){
//load xml file
// code for IE
if (window.ActiveXObject){
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("payroll.xml");
setupXML();
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument){
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load("payroll.xml");
xmlDoc.async=false;
xmlDoc.onload = setupXML;
}else{
alert('Your browser cannot handle this script');
}
}
function setupXML(){
//set variables to equal the right data
employees = xmlDoc.getElementsByTagName('employee');
employeeFirst = xmlDoc.getElementsByTagName('first');
employeeLast = xmlDoc.getElementsByTagName('last');
checkId = xmlDoc.getElementsByTagName('checkId');
checkAmt = xmlDoc.getElementsByTagName('checkAmt');
//
//run through the XML file, grab the data in the various
//arrays and then throw it down in the HTML after creating space for it
//
//write the html to put junk in there
//
var firstHalfDiv = "<table> \n <tr> \n <div id='DivWrapsHolder'>\n";
var lastHalfDiv = "</div> \n </tr> \n </table> \n";
document.write(firstHalfDiv);
for(i=0;i<employees.length;i++){
//
//populate the newly created table cells
//
document.write("<div id='DivWrapper_"+i+"' style='font-family:Arial, Helvetica, sans-serif;'>");
document.write("<table> \n\n");
document.write("<tr> \n");
document.write("<td id='FirstName_"+i+"'> \n <p>"+employeeFirst[i].firstChild.nodeValue+"</p>\n");
document.write("</td> \n");
document.write("<td id='LastName_"+i+"'> \n <p>"+employeeLast[i].firstChild.nodeValue+"</p>\n");
document.write("</td> \n");
document.write("<td id='CheckAmt_"+i+"'> \n <p>"+checkAmt[i].firstChild.nodeValue+"</p>\n");
document.write("</td> \n");
document.write("<td id='CheckId_"+i+"'> \n <p>"+checkId[i].firstChild.nodeValue+"</p>\n");
document.write("</td> \n");
document.write("</tr> \n");
document.write("</table> \n\n");
document.write("</div> \n\n");
}
document.write(lastHalfDiv);
}
</script>
also, the page never totally loads after it writes those xml values, it just seems stuck. i'm not sure if it's because i've incorrectly tried to implement the asynchronous part of things or not.
thanks for any help!!
john