• May 01, 2024, 04:57:31 pm

Author Topic: Basic working jscript examples  (Read 2545 times)

0 Members and 1 Guest are viewing this topic.

Offline Allstar12345

  • Allstar Software Founder
  • Administrator
  • Forum Genius
  • ******
  • Posts: 5,235
  • Reputation: 812
    • Allstar Software
  • Current Phone: : OnePlus 8 Pro, Xperia 10, Nexus 6p, Jolla Phone, Nokia N8, Nokia 808 PureView, BlackBerry Z30
Basic working jscript examples
« on: September 03, 2012, 06:44:22 pm »
Heres some example of basic working  jscript on the WRT platform.

Jscript popup

Code: [Select]
<!DOCTYPE html> <html> <head> <script type="text/javascript"> function myFunction() { alert("TEXT TO DISPLAY ")}</script> </head> <body> <input type="button" onclick="myFunction()" value="NAME OF BUTTON TO ACTIVATE COMMAND" /> </body>
</html>/




Confirm box

Code: [Select]
<!DOCTYPE html>
<html>
<body>

<p>Click the button to display a confirm box.</p>

<button onclick="myFunction()">BUTTON TEXT</button>

<p id="demo"></p>

<script type="text/javascript">
function myFunction()
{
var x;
var r=confirm("Confirm box info text");
if (r==true)
  {
  x="You pressed Yes!";
  }
else
  {
  x="You pressed No!";
  }
document.getElementById("demo").innerHTML=x;
}
</script>

</body>
</html>



Display the current year

Code: [Select]
<!DOCTYPE html>
<html>
<body>

<p id="demo">Click the button to display the full year of todays date.</p>

<button onclick="myFunction()">Try it</button>

<script type="text/javascript">
function myFunction()
{
var d = new Date();
var x = document.getElementById("demo");
x.innerHTML=d.getFullYear();
}
</script>

</body>
</html>




Display the current day

Code: [Select]
<!DOCTYPE html>
<html>
<body>

<p id="demo">Click the button to display todays day of the week.</p>

<button onclick="myFunction()">Try it</button>

<script type="text/javascript">
function myFunction()
{
var d = new Date();
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

var x = document.getElementById("demo");
x.innerHTML=weekday[d.getDay()];
}
</script>

</body>
</html>



Display the time

Code: [Select]
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
t=setTimeout('startTime()',500);
}

function checkTime(i)
{
if (i<10)
  {
  i="0" + i;
  }
return i;
}
</script>
</head>

<body onload="startTime()">
<div id="txt"></div>
</body>
</html>


Offline Allstar12345

  • Allstar Software Founder
  • Administrator
  • Forum Genius
  • ******
  • Posts: 5,235
  • Reputation: 812
    • Allstar Software
  • Current Phone: : OnePlus 8 Pro, Xperia 10, Nexus 6p, Jolla Phone, Nokia N8, Nokia 808 PureView, BlackBerry Z30
Re: Basic working jscript examples
« Reply #1 on: September 03, 2012, 06:44:36 pm »
Display popup on widget load

Code: [Select]

<html>
<head>
<script language="javascript" type="text/javascript">
alert("Welcome to my site")
</script>
</head>
</html>       

Offline Allstar12345

  • Allstar Software Founder
  • Administrator
  • Forum Genius
  • ******
  • Posts: 5,235
  • Reputation: 812
    • Allstar Software
  • Current Phone: : OnePlus 8 Pro, Xperia 10, Nexus 6p, Jolla Phone, Nokia N8, Nokia 808 PureView, BlackBerry Z30
Re: Basic working jscript examples
« Reply #2 on: September 03, 2012, 06:44:48 pm »
Google search

Code: [Select]
<html>
<head>


<center>
<FORM method=GET action="http://www.google.com/search">
<TABLE bgcolor="#FFFFFF"><tr><td>
<A HREF="http://www.google.com/">
<IMG SRC="http://www.google.com/logos/Logo_40wht.gif" <br></A>
<INPUT TYPE=text name=q size=31 maxlength=255 value="">
<INPUT TYPE=hidden name=hl value="en">
<INPUT type=submit name=btnG VALUE="Google Search">
</td></tr></TABLE>
</FORM>
</center>
<!-- Search Google -->


</head>
</html>


Offline Allstar12345

  • Allstar Software Founder
  • Administrator
  • Forum Genius
  • ******
  • Posts: 5,235
  • Reputation: 812
    • Allstar Software
  • Current Phone: : OnePlus 8 Pro, Xperia 10, Nexus 6p, Jolla Phone, Nokia N8, Nokia 808 PureView, BlackBerry Z30
Re: Basic working jscript examples
« Reply #3 on: September 03, 2012, 06:45:03 pm »
Close widget button

Code: [Select]
<html>
<head>
<!-- Start of Close Browser Script -->
<!-- When the "Close Window" button is clicked, this script
will close the browser window that the webpage is in.
-->
<script language="JavaScript">
<!--

function closeIt() {
  close();
}

// -->
</script>

<center>
<form>
<input type=button value="Close Window" onClick="closeIt()">
</form>
</center>

<!-- End of Close Browser Script -->

</head>
</html>

Offline Allstar12345

  • Allstar Software Founder
  • Administrator
  • Forum Genius
  • ******
  • Posts: 5,235
  • Reputation: 812
    • Allstar Software
  • Current Phone: : OnePlus 8 Pro, Xperia 10, Nexus 6p, Jolla Phone, Nokia N8, Nokia 808 PureView, BlackBerry Z30
Re: Basic working jscript examples
« Reply #4 on: September 03, 2012, 06:45:19 pm »
stopwatch

Code: [Select]
<body>

<SCRIPT LANGUAGE="JavaScript">
/*

var ms = 0;
var state = 0;

function startstop() {
if (state == 0) {
state = 1;
then = new Date();
then.setTime(then.getTime() - ms);
} else {
state = 0;
now = new Date();
ms = now.getTime() - then.getTime();
document.stpw.time.value = ms;
   }
}

function swreset() {
state = 0;
ms = 0;
document.stpw.time.value = ms;
}

function display() {
setTimeout("display();", 50);
if (state == 1)  {now = new Date();
ms = now.getTime() - then.getTime();
document.stpw.time.value = ms;
   }
}

window.onload=display
</SCRIPT>


<CENTER>
<FORM NAME="stpw">
Time:
<INPUT TYPE="text" Name="time">
<INPUT TYPE="BUTTON" Name="ssbutton" VALUE="Start/Stop" onClick="startstop()">
<INPUT TYPE="BUTTON" NAME="reset" VALUE="Reset" onClick="swreset()">
</FORM>
</CENTER>
</body>