Scrolling down and timer event

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

Pnirff
Ebase User
Posts: 21
Joined: Fri Jan 25, 2013 8:36 am

Scrolling down and timer event

#1

Postby Pnirff » Sat Mar 16, 2013 7:50 am

Hello,

I have two more things, that I have to implement into my chat. I have tried so many things and it doesn't work ... perhaps somebody could help me again:

1. I have a text area with a vertical scroll bar. Every time somebody enter a text into another text, the text will be copied to the end of the text area. This works fine. Now I want to scroll down in the text area, so that the user can see the entered text.
I have done the following:
In Html Elemet properties of the send button in the chat , I defined an ID "CHAT_SEND_BUTTON" and the Event "on_click" will be set to "chat_scroll_down(this)".
Now I develop a client script looks like this:

--------------------------------------------
$(document).ready(function(){
});

chat_scroll_down = function(element)
{
element.scrollTop = element.scrollHeight;
}
--------------------------------------------

Nothing happens. This function is also added to the web ressources in the form properties.

2. I want to add a timer control, so that from time to time, the text area
will be refreshed. I use nearly th following code:
------------------------------------------
$(document).ready(function()
{
});

window.setInterval(function() {
var elem = document.getElementById('CHAT_SEND_BUTTON');
elem.scrollTop = elem.scrollHeight;
}, 5000);
------------------------------------------

I have added both to the page and when I view the source, I can't see the code.

What do I wrong ...

Thank you very much
Manfred
0 x

Steve
Moderator
Moderator
Posts: 423
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

#2

Postby Steve » Mon Mar 18, 2013 12:38 pm

Hi Manfred,

I think your timer function looks fine.

If you have added the client script to your form, then you will only see a reference to the client script in the source e.g:

Code: Select all

<script src="clientScripts?clientScriptId=MY_CLIENT_SCRIPT&amp;ebz=1_1363611968484" type="text/javascript"></script>
You could try putting an alert in there and check that this is being called:

Code: Select all

window.setInterval&#40;function&#40;&#41; &#123; 
alert&#40;'Timer called'&#41;;
var elem = document.getElementById&#40;'CHAT_SEND_BUTTON'&#41;; 
elem.scrollTop = elem.scrollHeight; 
&#125;, 5000&#41;; 
Sometimes alerts can help you debug these things. Or the other option maybe the firebug plugin for firefox.

For the scroll, could you create a JQuery event for key down on your text area and check for enter key and then scroll to bottom?


Steve
0 x

Pnirff
Ebase User
Posts: 21
Joined: Fri Jan 25, 2013 8:36 am

#3

Postby Pnirff » Mon Mar 18, 2013 1:32 pm

Hello Steve,

I have added the script to the form into the tab "Web Resources" as a client script.
When I select the main page and open the view source in the context menu, I can´t see the reference.
Even when I put an alert into the script, i see nothing.

Thank alot
Manfred
0 x

Steve
Moderator
Moderator
Posts: 423
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

#4

Postby Steve » Mon Mar 18, 2013 2:34 pm

That is strange. I just tested this to make sure this was working.

I just tried adding a client script to a new form. The client script has:

Code: Select all

alert&#40;'Hello'&#41;;
Then I ran the form and the alert was printed out.

Are you 100% sure that the client script is listed in the Web Resources part of the the form and the apply is ticked?

Steve
0 x

Pnirff
Ebase User
Posts: 21
Joined: Fri Jan 25, 2013 8:36 am

#5

Postby Pnirff » Mon Mar 18, 2013 6:14 pm

Hello,

yes. I am 100% sure, but when I remove the lines:
$(document).ready(function()
{
});

so that the script look like :
window.setInterval(function() {
var elem = document.getElementById('CHAT_SEND_BUTTON');
elem.scrollTop = elem.scrollHeight;
}, 5000);

it works fantastic ... I am not 100% familiar with javascript. Sorry for that.
But thx anyway :)
Manfred
0 x


Who is online

Users browsing this forum: Bing [Bot] and 36 guests