Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Update DIV html from text file on server

    What I want to do is to update a series of 10 divs, a to j, with the contents of a text file that is saved to the server. Each line in the text file goes to it's respective div (line 1 of text goes to div 'a', etc.), ignoring any lines past 10.

    I can use a TXT or CSV on the server.

    Ideally, I would like to load the contents of the text into a variable so I can then parse it out, apply my HTML tags and then place it into the innerHTML of a DIV.

    You can view it live here: http://00010ck.wcomhost.com/home.html

    I am using jquery-1.10.2.js to provide the load event.

    Code:
    function onLoad() {
    $("#result").load("calendar/eventList.txt"); // loads text file to page // This works fine and is visable on the HTML page.
    	var fileContents = document.getElementById('result').innerText; // I've tried innerHTML too
    	document.getElementById('a').innerHTML=fileContents; // This line pulls the original content of div 'result' rather then the new contents loaded into the div by the load.
    }
    The intent here: I have a agenda that is saved to the text file (each line is an event) and would like them to appear in the DIVS to provide a list of events. If it is possible to skip lines if the date is past, that would be ideal, but is not the focus of this question.

    Thanks in advance!

    - Brian

  • #2
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Resolved

    Resolved.

    Here is the assigning the contents to a variable:
    Code:
    function onLoad() {
    	var fileContents = getFile("eventList.txt")
    }
    Here is the function used to get the file contents:
    Code:
    function getFile(filename) { oxmlhttp = null;
        try
          { oxmlhttp = new XMLHttpRequest();
            oxmlhttp.overrideMimeType("text/xml");
          }
        catch(e)
          { try
              { oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
              }
            catch(e)
              { return null;
              }
          }
        if(!oxmlhttp) return null;
        try
          { oxmlhttp.open("GET",filename,false);
            oxmlhttp.send(null);
          }
        catch(e)
          { return null;
          }
        return oxmlhttp.responseText;
      }


  •  

    Tags for this Thread

    Posting Permissions

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