SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Little Javascript Issue - CSV File

    I've got a little issue that hopefully someone can help out with. I have a CSV file called names2.csv with the following data

    Name,Date \n
    George,6/15/2010 \n
    Smith,6/11/2010 \n

    And here's the code

    Code:
    <html>
    <head>
    <title>CSV &amp; Date parser</title>
    <script type="text/javascript">
    // From: http://codingforums.com/showthread.php?t=198171
    
    
    function checkCSVdate() {
    // ckDate = document.getElementById('dinfo').value;
      
    var currentTime = new Date()
    var month = currentTime.getMonth() + 1
    var day = currentTime.getDate()
    var year = currentTime.getFullYear()
    
    ckDate = (month + "/" + day + "/" + year);
    
    var str = '';
    fso  = new ActiveXObject("Scripting.FileSystemObject"); 
    fin  = fso.OpenTextFile("names2.csv", 1, false, 0);
    var line = fin.ReadAll();
      var tmp = line.split('\n');
      for (var i=0; i<tmp.length; i++) {
        temp = tmp[i].split(',');
        if (ckDate == temp[1]) { str += tmp[i]; }
      }
      if (str == '') { document.getElementById('mtchDiv').innerHTML = 'No matches found'; }
                else { document.getElementById('mtchDiv').innerHTML = str; }
    }
    
    onload = function() {
    
        checkCSVdate();
    
    }
    
    </script>
    </head>
    <body>
    <div id="mtchDiv"></div>
    </body>
    </html>
    Since the data file has a line with 6/15/2010, it should return "George", right? It returns "No Matches Found".

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,871
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    What version of Internet Explorer is your intranet running?
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've tested it on IE8 and FFox3

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,871
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    new ActiveXObject("Scripting.FileSystemObject");

    is an Internet Explorer proprietary command so it isn't going to work anywhere except on IE. With more recent versions of IE such as IE7 and IE8 it will also depend on the system security settings as to whether it will run. Most such activeX controls are disabled in those versions of IE as they present a security hole when enabled.

    I'd expect the code to only work on IE6 unless you specifically adjust the security settings in IE7 or IE8 to allow it to run there as well.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

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