Javascript getGMT times and Forms

new BookmarkLockedFalling
Janet
Global Moderator
*****

Janet Avatar

Posts: 276

Post by Janet on Sept 11, 2008 9:05:29 GMT -5

This is the stripped down html code

<html>
<script type='text/javascript'>
function getGMT() {
date = new Date();
gmt = date.toGMTString();
exp = gmt.substring();
document.formUTC.gmt.value = exp;
setTimeout('getGMT()', 1000);
}
</script>
</head>
<font face='verdana'>
<body onLoad='getGMT();'>

<form name='formUTC'>
<h1>UTC Time</h1>
<br>

UTC (GMT)
<input type='text' size='36' name='gmt'>
<br /><br />

</form>

</body>
</html>


This is the non-working RB code


cls
html "<script type='text/javascript'>
function getGMT() {
date = new Date();
gmt = date.toGMTString();
exp = gmt.substring();
document.formUTC.gmt.value = exp;
setTimeout('getGMT()', 1000);
}
</script>"
html "<font face='verdana'>"

print: print
print "UTC Time Changes"
print: print

html "<form name='formUTC'>"
html " UTC (GMT) "
html "<input type='text' size='42' name='gmt'>"
html "<br /><br />"
html "</form>"


The time doesn't show in RB. I've read through this discussion: From HTML textarea to RB textarea and I'm guessing it's a matter of Carl's statement
Run BASIC does not maintain the contents of widgets that it didn't create. It doesn't even know they are there.

At the end of that discussion is a simple demo using an RB button.

Has the RB button been implemented in RB beta 2?
Can my demo be made to work using this technique?
How would I change the javascript to place the information in a textarea rather than a form?
I'm not intent upon keeping real time. I'd just like to be able to press a button and get the time, but I want to be able to capture that information in a string so I can then parse it and make two times from it (Eastern USA and Central Asia).

Thanks for any help with this.

Janet

Last Edit: Sept 11, 2008 9:07:35 GMT -5 by Janet
[br]
StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

Post by StefanPendl on Sept 12, 2008 2:47:18 GMT -5

The problem here is, that the display is already a form, so you have nested forms.
We are closing the RB form just before our code and use the RB forms ending tag for our UTC form.

Below find some working cls
html "</form>"
html "<script type='text/javascript'>
function getGMT() {
date = new Date();
gmt = date.toGMTString();
exp = gmt.substring();
document.formUTC.gmt.value = exp;
setTimeout('getGMT()', 1000);
}
</script>"
html "<font face='verdana'>"

print: print
print "UTC Time Changes"
print: print

html "<form name='formUTC'>"
html " UTC (GMT) "
html "<input type='text' size='42' name='gmt'>"
html "<br /><br />"

'uncomment the following to let the user start the time display
'html "<input type='button' value='Display Time' onclick='getGMT();'/>"

'the following will start the time display immediately
html "<script type='text/javascript'> getGMT() </script>"
Last Edit: Sept 12, 2008 2:50:38 GMT -5 by StefanPendl
[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
Janet
Global Moderator
*****

Janet Avatar

Posts: 276

Post by Janet on Sept 12, 2008 8:00:43 GMT -5

PERFECT! 8-)
Thank you so much, Stefan. I know I could have used the native time$() command but I'm running my programs on Jerry's runbasicnet, which is in a different time zone than me. When I saw this snippet, I really wanted to try it. I've been unsuccessful converting other javascript functions, but I believe your conversion has just brought me a couple of steps forward. Thanks again, Stefan.

I just love this Run BASIC community. ;D

Janet
[br]
kokenge
Senior Member
****

kokenge Avatar

Posts: 261

Post by kokenge on Sept 12, 2008 9:20:32 GMT -5

If you don't like managing forms, you may try this.
But both work fine.

cls
html "<script type='text/javascript'>
function getGMT() {
date = new Date();
gmt = date.toGMTString();
document.getElementById('utc').innerHTML = gmt;
setTimeout('getGMT()', 1000);
}
</script>"
html "<font face=verdana>"
html "<p>UTC Time Changes<p> UTC (GMT) <div id=utc></div>"
html "<script type='text/javascript'> getGMT() </script>"


If you want to dress it up a little replace the html display with:
html "<table border=1><tr><td colspan=2 bgcolor=tan align=center>UTC Time Changes</tr><td bgcolor=tan>UTC (GMT</td><td id=utc></td></tr></table>"


Just another way of doing the same thing.
HTH
Last Edit: Sept 12, 2008 9:39:58 GMT -5 by kokenge
Janet
Global Moderator
*****

Janet Avatar

Posts: 276

Post by Janet on Sept 12, 2008 10:17:51 GMT -5

Hi, Dan. Taking it out of a form is definitely a better option. Keeping it inside a form causes RB to default to the login page if the page is rendered again. So, it's okay for a one time use static page only. Ideally, I want to be able to to place the information in a textarea so I can retrieve it using the beta2 command: #request get$("gmt"). I did buy a JavaScript book, but the learning curve isn't as happy and carefree as either Liberty BASIC or Run BASIC. :)

I do appreciate the alternative methods. They're definitely helping me to sort things out. Karma +1 to Dan. ;)
Last Edit: Sept 12, 2008 10:19:15 GMT -5 by Janet
[br]
kokenge
Senior Member
****

kokenge Avatar

Posts: 261

Post by kokenge on Sept 12, 2008 10:40:07 GMT -5

Javascript heh! Mercy!
Google is doing some interesting JS stuff with it in it's new Chrome browser.
You may want to watch some of these to help you get started.
video.google.com/videosearch?q=javascript+tutorial&hl=en&emb=0&aq=0&oq=javascript+t#

Good luck...

BTW, you can put javascript stuff in a textarea or textbox now with the following code.

cls
html "<script type='text/javascript'>
function getGMT() {
date = new Date();
gmt = date.toGMTString();
document.getElementById('utc').value = gmt;
setTimeout('getGMT()', 1000);
}
</script>"
html "<font face=verdana>"
html "<p>UTC Time Changes<p> UTC (GMT)"

TEXTBOX #utc, utc$
#utc setid("utc")

html "<script type='text/javascript'> getGMT() </script>"


Just another option
Last Edit: Sept 12, 2008 10:57:48 GMT -5 by kokenge
Janet
Global Moderator
*****

Janet Avatar

Posts: 276

Post by Janet on Sept 12, 2008 11:43:21 GMT -5

Woohoo! Stefan and Dan, you guys rock!! I can get the time in a variable now. ;D

cls
html "<script type='text/javascript'>
function getGMT() {
date = new Date();
gmt = date.toGMTString();
document.getElementById('utc').value = gmt;
setTimeout('getGMT()', 1000);
}
</script>"
html "<font face=verdana>"
html "<p>UTC Time Changes<p> UTC (GMT)"

TEXTBOX #utc, utc$
#utc setid("utc")

html "<script type='text/javascript'> getGMT() </script>"

print: print
link #timeGMT, " Get GMT ", [timeGMT]
print: print
wait

[timeGMT]
utc$ = #utc contents$()
print utc$
wait

This works in beta1 and beta2 of RB 1.01. Not sure if it works in the non-beta version. Looks like another Run BASIC wikispaces contribution in the making. ;)

Dan, I've bookmarked the video and I'll watch it sometime next week. Thanks again.
Janet

[br]
StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM