JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 13th, 2013, 09:55 AM
pw111970 pw111970 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 pw111970 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 3 sec
Reputation Power: 0
Set variables in Javascript from Excel spreadsheet

I have a Javascript that displays a timer on a screen and when the timer reaches a set value it changes the colour of the backround to 'Red'. I need to be able to dynamically change this variable, based on a set of circumstances. I was wondering is it possible to set the value of the Javascript variable from a cell in Excel. I have provided my code below, clock_limit is the variable I want to be able to set using a cell from an Excel spreadsheet.


Code:
<script type="text/javascript">
        var minutesLabel = document.getElementById("minutes");
        var secondsLabel = document.getElementById("seconds");
        var clock_limit = 828;
        var totalSeconds = 0;
        setInterval(setTime, 1000);

        function setTime()
        {
            ++totalSeconds;
            secondsLabel.innerHTML = pad(totalSeconds%60);
            minutesLabel.innerHTML = pad(parseInt(totalSeconds/60));
        
if (totalSeconds> clock_limit)
        {
          document.body.style.backgroundColor = "red";
        }
        else
        {
          document.body.style.backgroundColor = "green";
        }

}

        function pad(val)
        {
            var valString = val + "";
            if(valString.length < 2)
            {
                return "0" + valString;
            }
            else
            {
                return valString;
            }
        }
    </script>

Reply With Quote
  #2  
Old February 13th, 2013, 01:14 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,939 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 9 h 12 m 42 sec
Reputation Power: 7053
Note: Java and JavaScript are very different programming languages.

JavaScript that is executed on a web page cannot read or write files of any type.

If the Excel file is on the server, you could use a helper language like PHP to read the Excel file and pass the value along to JavaScript. The workflow for this is not that complicated, but you'll need to use a third party library for parsing the Excel file. This can be done with other server side languages (other than PHP) too.

If the Excel file is on the client, you will either need to upload it to the server, or use a client-side language that is able to elevate its privileges (like Flash or Java). The workflow for this is not particularly simple.
__________________
PHP FAQ
How to program a basic, secure login system using PHP

Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
  #3  
Old February 14th, 2013, 10:06 AM
pw111970 pw111970 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 pw111970 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 3 sec
Reputation Power: 0
Thank you for a prompt reply.

Quote:
Originally Posted by E-Oreo
Note: Java and JavaScript are very different programming languages.

JavaScript that is executed on a web page cannot read or write files of any type.

If the Excel file is on the server, you could use a helper language like PHP to read the Excel file and pass the value along to JavaScript. The workflow for this is not that complicated, but you'll need to use a third party library for parsing the Excel file. This can be done with other server side languages (other than PHP) too.

If the Excel file is on the client, you will either need to upload it to the server, or use a client-side language that is able to elevate its privileges (like Flash or Java). The workflow for this is not particularly simple.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Set variables in Javascript from Excel spreadsheet

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap