Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Time.now "stuck" in Javascript Function.
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
Nick S  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 15:36
From: Nick S <nds...@iinet.net.au>
Date: Sun, 8 Nov 2009 07:36:29 -0800 (PST)
Local: Sun 8 Nov 2009 15:36
Subject: Time.now "stuck" in Javascript Function.
Novice RoR programmer here, I've run into a bit of a stumbling block,
concerning Time.now seemingly not updating in between JS function
calls.

My code is as follows:

function test()
{
document.getElementById("chatbox").value += "<%= Time.now %>" + "\n";

}

...

<textarea id="chatbox" rows="10" cols="80" class="chatbox"
readonly="true" onclick="test();">
</textarea>

Basically, clicking the textarea "chatbox" will add a line with the
current time, and unfortunately, every click on the textarea results
in the identical line being written, which is the time that the page
was loaded.

Is there any way I could get Time.now to update with every click?

Thanks in advance!

Nick.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Frederick Cheung  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 15:57
From: Frederick Cheung <frederick.che...@gmail.com>
Date: Sun, 8 Nov 2009 07:57:14 -0800 (PST)
Local: Sun 8 Nov 2009 15:57
Subject: Re: Time.now "stuck" in Javascript Function.
On Nov 8, 3:36 pm, Nick S <nds...@iinet.net.au> wrote:

> function test()
> {
> document.getElementById("chatbox").value += "<%= Time.now %>" + "\n";

> }

> <textarea id="chatbox" rows="10" cols="80" class="chatbox"
> readonly="true" onclick="test();">
> </textarea>

> Basically, clicking the textarea "chatbox" will add a line with the
> current time, and unfortunately, every click on the textarea results
> in the identical line being written, which is the time that the page
> was loaded.

That's completely normal - At the point that the template is rendered
all of your <%= are evaluated - if you look at the source in the
browser you won't see any of your ruby code (and even if you could,
what's your browser supposed to do with ruby). If you need some ruby
code evaluated you need to make a request to the server

Fred


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nick S  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 16:00
From: Nick S <nds...@iinet.net.au>
Date: Sun, 8 Nov 2009 08:00:31 -0800 (PST)
Local: Sun 8 Nov 2009 16:00
Subject: Re: Time.now "stuck" in Javascript Function.
Ahh I see, thank you very much for your help Frederick!

On Nov 9, 12:57 am, Frederick Cheung <frederick.che...@gmail.com>
wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marnen Laibow-Koser  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 17:17
From: Marnen Laibow-Koser <rails-mailing-l...@andreas-s.net>
Date: Sun, 8 Nov 2009 18:17:25 +0100
Local: Sun 8 Nov 2009 17:17
Subject: Re: Time.now "stuck" in Javascript Function.

Frederick Cheung wrote:
> On Nov 8, 3:36 pm, Nick S <nds...@iinet.net.au> wrote:
>> Basically, clicking the textarea "chatbox" will add a line with the
>> current time, and unfortunately, every click on the textarea results
>> in the identical line being written, which is the time that the page
>> was loaded.

> That's completely normal - At the point that the template is rendered
> all of your <%= are evaluated - if you look at the source in the
> browser you won't see any of your ruby code (and even if you could,
> what's your browser supposed to do with ruby). If you need some ruby
> code evaluated you need to make a request to the server

But in this case, you probably don't need a server request -- I think
JavaScript has an equivalent to Time.now.

In any case, I would advise against using ERb in JavaScript...

> Fred

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
--
Posted via http://www.ruby-forum.com/.

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google