Results 1 to 12 of 12

Thread: I need someone who knows something about Javascript

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Senior Member beelzebub's Avatar
    Join Date
    Aug 2004
    Location
    California
    Posts
    223
    Ok so i solved the problem, I will show the solution as a reference for anyone else who has this problem.

    So my solution is not an all around solution. I cant get the getElementsByTagName('tag') function to work so I had to refer to the URL tag by postion not name. This will all make sense in a minute.

    So here is the new code:

    <script language="JavaScript">
    var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    function loadXML(xmlFile) {
    xmlDoc.async="false";
    xmlDoc.onreadystatechange=verify;
    xmlDoc.load(xmlFile);
    }

    function verify() {
    if(xmlDoc.readyState!=4)
    return false;
    }

    function traverse(tree) {
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth();
    var day = date.getDate();
    for(var i=0; i<tree.childNodes.length;i++){
    document.write('<TR><TD>');
    var date = tree.childNodes[i].getAttribute("EXPIRES").split("/");
    var color,text;
    if(date[2] < year){
    if(date[0] < month){
    if(date[1] < day){color = "#E03127"; text = "white";}}}
    else{color = "silver"; text = "#000000";}
    document.write('<DIV CLASS = "header" STYLE = "background-color:'+color+'; color:'+text+'">'+tree.childNodes[i].childNodes[0].text+'</DIV>');
    document.write('<DIV CLASS = "general">'+tree.childNodes[i].childNodes[1].text+'</DIV>');
    for(var n=0; n<tree.childNodes[i].childNodes.length;n++){
    if(tree.childNodes[i].childNodes[n].tagName == 'URL'){
    document.write('<DIV><A HREF = "'+tree.childNodes[i].childNodes[2].text+'" TARGET = "_blank">'+tree.childNodes[i].childNodes[3].text+'</A></DIV>');

    }
    }
    document.write('<HR></TD></TR>');
    }


    }

    function initTraverse(file) {
    loadXML(file);
    var doc=xmlDoc.documentElement;
    traverse(doc);
    }

    initTraverse("events.xml");
    </script>

    I added a for loop (identified in red) that will cycle through all of the child nodes in the <EVENT> tag (unfortunetly this causes the script to be slower). In that for loop I added an if statement that tells the browser to write an <A HREF> if the child node it is currently cycling through titled URL. Otherwise it does nothing. This has two benefits. One I dont need to specify another if statement that says dont write anything when it encounters the URL_TITLE tag, and it does nothing if there is no URL tag. allowing me to omit it when ever I please. So the reason why it is not all around is because instead of the script saying <A HREF = "'...getElementsByTagName('URL')'"> (insterting the text of the URL tag based on tag name) it insterts the text of the URL based on the URLs position in the XML document. So, I am unable to move the URL tag (though i can omit it) or insert any new tags above it. Feel free to tell me how to change that, by the way?

    Oh ya if you were wondering the date stuff at the top of the original for loop checks to see if the event is old or upcoming. I added an attribute to <EVENT> called EXPIRES which stores a date (mm/dd/yyyy) this date is split at each /. The if statements compair mm to the current month and so forth. If the date is still younger than the expiration date it gives the <div> for the events title a silver background otherwise it give it a redish background with white text.

    Click here to see the end result of my labors.
    Last edited by beelzebub; July 24th, 2006 at 22:19 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •