Monday, February 28, 2011

Monday, Feb. 28th 2011


<?php
function create_table($data) {
echo "<table border=\"1\">";
reset($data); //Remember this is used to point to the beginning
$value = current($data);
while ($value) {
echo "<TR><TD>" . $value . "</td></tr>\n";
$value = next($data);
}
echo "</table>";
}

$my_array = array('Line one.', 'Line two.', 'Line three.');
create_table($my_array);
?>

Friday, February 25, 2011

Friday, August 25th 2011


<?php

//create short variable names
$name = $_POST['name'];
$email = $_POST['email'];
$feedback = $_POST['feedback'];

//set up some static information
$toaddress = "alfred.jensen@laservault.com";
$subject = "Feedback from web site";

$mailcontent = "Customer name: " . $name . "\n" .
"Customer email: " . $email . "\n" .
"Customer comments: \n" . $feedback . "\n";

$fromaddress = "From: alfred.jensen@laservault.com";
//invoke mail() function to send mail
mail($toaddress, $subject, $mailcontent, $fromaddress);

?>
<html>
<head>
<title>Bob's Auto Parts - Feedback Submitted</title>
</head>
<body>
<h1>Feedback submitted</h1>
<p>Your feedback has been sent.</p>
</body>
</html>



Here is another tutorial which I modified to make the construction of the submenu based on an array rather than doing it by hand.


<head>
<title>TLA Consulting Pty Ltd</title>
<style type = "text/css">

h1 {color:white; font-size:24pt; text-align:center; font-family:arial,sans-serif;}

.menu {color:white; font-size:12pt; text-align:center; font-family:arial, sans-serif; font-weight:bold;}

td {background:black;}

p {color:black; font-size:12pt; text-align:justify; font-family:arial, sans-serif}

p.foot {color:white; font-size:9pt; text-align:center; font-family:arial, sans-serif; font-weight:bold;}

a:link, a:visited, a:active {color:white}

</style>

</head>

<body>

<table width="100%" cellpadding="12" cellspacing="0" border="0">
<tr bgcolor="black">
<td align="left"><img src="logo.gif" alt="TLA logo" height="70" width="70"></td>
<td>
<h1>TLA Consulting</h1>
</td>
<td align="right"><img src ="logo.gif" alt="TLA logo" height="70" width="70" /></td>
</tr>
</table>
<!-- menu -->
<table width = "100%" bgcolor="white" cellpaddinng="4" cellspacing="4">
<tr>
<?php
$menuItems=array("Home","Contact","Services","Site Map");
$divider = count($menuItems);
$percentage = (100/$divider) . "%";
for ($i=0; $i<=$divider; $i++) {
?>
<td width="">;
<span class="menu"></span>
</td>
<?php } ?>
</tr>
</table>

Thursday, February 24, 2011

Thursday 24 Feb 2011

I finally got this to work:



<?php
//create short variable name
$Document_Root = $_SERVER['DOCUMENT_ROOT'];



?>
<html>
<head>
<TITLE>Bob's Auto Parts - Customer Orders</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Customer Orders</h2>
<?php

$orders = file("$Document_Root/Book/orders/orders.txt");

$number_of_orders = count($orders);

if ($number_of_orders == 0) {
echo "<P><STRONG>No orders pending.
Please try again later.</strong></p>";
}

echo "<table border=\"1\">\n";
echo "<tr><th bgcolor=\"#CCCCFF\">Order Date</th>
<th bgcolor=\"#CCCCFF\">Tires</th>
<th bgcolor=\"#CCCCFF\">Oil</th>
<th bgcolor=\"#CCCCFF\">Spark Plugs</th>
<th bgcolor=\"#CCCCFF\">Total</th>
<th bgcolor=\"#CCCCFF\">Address</th>
<tr>";

for ($i = 0; $i<$number_of_orders; $i++) {
//split up each line
$line = explode("\t", $orders[$i]);
// keep only the number of items ordered
$line[1] = intval($line[1]);
$line[2] = intval($line[2]);
$line[3] = intval($line[3]);

//output each order
echo "
<td>" . $line[0]."
<td align =\"right\">" . $line[1] . "</td>
<td align =\"right\">" . $line[2] . "</td>
<td align = \"right\">" . $line[3] . "</td>
<td align = \"right\">" . $line[4] . "</td>
<td>" . $line[5] . "
</tr>";
}

echo "</table>";


?>

Tuesday, February 22, 2011

Tuesday, February 22 2011





<asp:TextBox ID="txtValue1" runat="server"></asp:TextBox>
<asp:DropDownList ID="firstOperator" runat="server">
<asp:ListItem>+</asp:ListItem>
<asp:ListItem>-</asp:ListItem>
<asp:ListItem>*</asp:ListItem>
<asp:ListItem>/</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="txtValue2" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblResult" runat="server"></asp:Label>
<br />
<asp:Button ID="btnCalculate" runat="server" Text="Calculate" /></asp:Label>









Public Class Calculator

Public Function Add(ByVal a As Double, ByVal b As Double) As Double
Return a + b
End Function

Public Function Subtract(ByVal a As Double, ByVal b As Double) As Double
Return a - b
End Function

Public Function Multiply(ByVal a As Double, ByVal b As Double) As Double
Return a * b
End Function

Public Function Divide(ByVal a As Double, ByVal b As Double) As Double
Return a / b
End Function

End Class

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub firstOperator_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles firstOperator.SelectedIndexChanged
If txtValue1.Text.Length > 0 AndAlso txtValue2.Text.Length > 0 Then

Dim result As Double = 0
Dim value1 As Double = Convert.ToDouble(txtValue1.Text)
Dim value2 As Double = Convert.ToDouble(txtValue2.Text)
Dim myCalculator As New Calculator()

Select Case firstOperator.SelectedValue
Case "+"
result = myCalculator.Add(value1, value2)
Case "-"
result = myCalculator.Subtract(value1, value2)
Case "*"
result = myCalculator.Multiply(value1, value2)
Case "/"
result = myCalculator.Divide(value1, value2)
End Select
lblResult.Text = result.ToString()
Else
lblResult.Text = String.Empty
End If
End Sub
End Class

Monday, February 21, 2011


<?php
$absolutePath = __FILE__;

echo $absolutePath . "
";

$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];


echo $DOCUMENT_ROOT . "
";

$current_dir = getCwd();

echo $current_dir;
?>

Friday, February 18, 2011

Monday 2/18/2011

I've actually been working on other things this week, but this is the first time I've been able to do some tutorials.


/**
* @author Alfred
*/
<html>
<body>
<script type="text/javascript">
//create new date object
var someDate = new Date("31 Jan 2003 11:59");
//retrieve the first four values using the appropriat get methods
document.write("Minutes = " + someDate.getMinutes() + "
");
document.write("Year = " + someDate.getFullYear() + "
");
document.write("Month = " + someDate.getMonth() + "
");
document.write("Date = " + someDate.getDate() + "
");
// Set the minutes to 34
someDate.setMinutes( 34 );
document.write("Minutes = " + someDate.getMinutes() + "
");
// Reset the date
someDate.setDate(32);
document.write("Date = " + someDate.getDate() + "
");
document.write("Month = + someDate.getMonth() + "
");
</script>
</body>
</html>


Here is another tutorial on Rounding



<script type="text/javascript">

function roundNumber(num){
document.write("round() = " + Math.round(num));
document.write("<br>");
document.write("floor() = " + Math.floor(num));
document.write("<br>");
document.write("ceil() = " + Math.ceil(num));
document.write("<br>");
}

var numberToRound = prompt("Please enter a number", "");

roundNumber(numberToRound);

numberToRound = 49.293;
document.write("Number to round = " + numberToRound + "<BR>");
roundNumber(numberToRound);

numberToRound = 58.63;
document.write("Number to round = " + numberToRound + "<BR>");
roundNumber(numberToRound);

</script>

Friday, February 11, 2011

Friday 2/11/11


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>className Property</title>
<style type="text/css">
.special {font-size:16pt; color:red;}
</style>
<script type="text/javascript">
function toggleSpecialStyle(elemID) {
var elem = (document.all) ? document.all(elemID) :
document.getElementById(elemID);
if (elem.className == "") {
elem.className = "special";
} else {
elem.className = "";
}
}
</script>
</head>
<body>
<h1>className Property Lab</h1>
<hr />
<form name="input">
<input type="button" value="Toggle Class Name" onclick="toggleSpecialStyle('head1')" />
</form>
<br />
<h1 id="head1">Article I</h1>
<P>Congress shall make no law respecting an establishment of religion, or prohibiting the free exericse thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the government for a redress of grievances.</P>
<h1>Article II</h1>
<P>A well regulated militia, being necessary to the security of a free state, the right of the people to keep and bear arms, shall not be infringed.</P>
</body>
</html>

Here is something else I wrote:


<html>
<head>
<title>clientHeight and clientWidth Properties</title>
<link rel=stylesheet HREF="bibleStyles.css" type="text/css">
<script type="text/javascript">
function getInfo(){
var divWidth = document.getElementById("myDIV").clientWidth;
var divHeight = document.getElementById("myDIV").clientHeight;
var lineText = "Width = " + divWidth + " Height = " + divHeight;
var lineTextNode = document.createTextNode(lineText);
var newP = document.createElement('p');
var divInfo = document.getElementById('divInfo');
newP.appendChild(lineTextNode);
divInfo.appendChild(newP);
alert(document.styleSheets.length);
}
function changeWidth() {
document.styleSheets[0].insertRule("#myDiv {width:400px;}",0);
getInfo();
}
</script>

</head>
<body>
<button type="button" onclick="getInfo()">Get info</button>

<button type="button" onclick="changeWidth()">Change width</button>
<div id="myDIV">
<p>Lorem ipsum dolor sit amet, consectetaur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim adminim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>

<div id="divInfo">

</div>

</body>
</html>



Here is another tutorial.


<script language="JavaScript">
var varA=2;
var varB=5;

if (varA == 0) {
document.write("varA == 0");
}
else {
if ((varA * 2) >= varB) {
document.write("(varA *2) >= varB");
}
else {
document.write("(varA*2) < varB");
document.write(varB);
}

}

</script>


Here is another tutorial 0 = False 1 = True


<script language="JavaScript">
var temp = 1;
var temp2 = 0;

if (temp == true) {
document.write("statement1 is true");
}
else {
document.write("statement1 is false");
}

document.write('
')
if (temp2 == true) {
document.write("statement2 is true");
}
else {
document.write('statement2 is not true');
}
</script>


Here is another tutorial:


<script language ="JavaScript">
var response = confirm("Do you want to proceed with this book? Click OK to proceed otherwise click Cancel.")

if (response == true)
{
alert("A fine choice!");
} else {
alert("A not so fine choice!");
}

</script>


Here is another tutorial


<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>CSS Resolution Demo</title>
<link rel="StyleSheet" href="basic.css" type="text/css" />
<script type="text/javascript">
//Define a variable called cssName and a message
//called resolutionInfo
var cssName;
var resolutionInfo;
//If the width of the screen is less than 650 pixels
if (screen.availWidth < 650) {
// define the style Variable as teh low-resoltion style
cssName = "lowres.css";
resolutionInfo = 'low resoltiion';
// or if the width of the screen is less than 1000 pixels
} else {
if (screen.availWidth > 1000) {
//define the style variable as the high-resolution style
cssName = "highres.css";
resolutionInfo = 'high resoltion';
//otherwise
} else {
// define the style Variable as the mid-resolution style
cssName = 'lowres.css';
resolutionInfo = 'medium resoltion';
}
}
document.write( '<link rel="StyleSheet" href="' + cssName + '" type="text/css" />');
</script>
</head>
<body>
<script type="text/javascript">
document.write('

Applied Style:' + resolutionInfo + '

');
</script>
</body>

Thursday, February 10, 2011

Thursday, 2/10/11


<?php
//example 3-1-4.php

$a = 1;
echo "is_numeric($a) = " . (is_numeric($a) ? "true" : "false") . "\n";

echo "
";

$a = 1.5;
echo "is_numeric($a) = " . (is_numeric($a) ? "true" : "false") . "\n";

echo "
";

$a = true;
echo "is_numeric($a) = " . (is_numeric($a) ? "true" : "false") . "\n";

echo "
";

$a = "Test";
echo "is_numeric($a) = " . (is_numeric($a) ? "true" : "false") . "\n";

echo "
";

$a = '3.5';
echo "is_numeric($a) = " . (is_numeric($a) ? "true" : "false") . "\n";

echo "
";

$a = "3.5E27";
echo "is_numeric($a) = " . (is_numeric($a) ? "true" : "false") . "\n";

echo "
";

$a = "0x19";
echo "is_numeric($a) = " . (is_numeric($a) ? "true" : "false") . "\n";

echo "
";
echo "
";
echo "
";

//example 3-1-5.php

$a = 123;
echo "is_int($a) = " . (is_int($a) ? "true" : "false") . "\n";

$a = '123';
echo "is_int($a) = " . (is_int($a) ? "true" : "false") . "\n";

echo "
";
echo "
";
echo "
";

// example 3-1-11.php

$a=50.3;
$b=50.4;
$c=100.7;

if ($a + $b == $c) {
echo "$a + $b == $c\n";
}
else {
echo "$a + $b != $c\n";
}

echo "
";
echo "
";
echo "
";

for ($i = 0; $i < 100; $i += 0.1) {
if ($i == 50) echo '$i == 50' . "\n";
if ($i >= 50 && $i < 50.1) echo '$i >= 50 && $i < 50.1' . "\n";
}
?>


Next post



<?php
// Example 3-2-8.php
function GeneratePassword($min = 5, $max = 8) {
$ValidChars = "abcdefghijklmnopqrstuvwxyz123456789";
$max_char = strlen($ValidChars) - 1;
$length = mt_rand($min, $max);
$password = "";
for ($i = 0; $i < $length; $i++) {
$password .= $ValidChars[mt_rand(0, $max_char)];
}
return $password;
}

echo "New password = " . GeneratePassword() . "\n";
echo "New Password = " . GeneratePassword() . "\n";
?>


This is a really cool tutorial on how to make a bar graph. I can't say i completely understood it.


<?php
// Example 3-3-4.php
define('BAR_LIN', 1);
define('BAR_LOG', 2);

function ShowChart($arrData, $iType = BAR_LIN, $iHeight = 200) {
echo "<table border=0><tr>";
$max = 0;
foreach($arrData as $y) {
if($iType == BAR_LOG) {
$y = log10($y);
}
if ($y > $max) $max = $y;
}
$scale = $iHeight / $max;

foreach($arrData as $x=>$y) {
if ($iType == BAR_LOG) {
$y = log10($y);
}
$y = (int)($y*$scale);
echo "<td valign=bottom>
<img src='dot.png' width=10 height=$y>
</td>
<td width=5> </td>";
}
echo "</tr></table>";
}

$arrData = array(
150,
5,
200,
8,
170,
50,
3
);

echo '<html><body>';

echo 'show chart with linear scale';
ShowChart($arrData, BAR_LIN);

echo '
Show chart with logarithmic scale';
ShowChart($arrData, BAR_LOG);

echo '</body></html>';

?>

Here is a post on an introduction to arrays.



<?php
$my_array = array();

$pets = array('Tweety', 'Sylvester', 'Bugs', 'Wile E.');

$person = array('Bill', 'Jones', 24, 'CA');
$customer = array('first' => 'Bill', 'last' => 'Jones', 'age' => 24, 'state' => 'CA');

print "

Pet number 1 is named '$pets[0]'.

\n";
print "

The person's age is $person[2].

\n";
print "

The customer's age is {$customer['age1']}.

\n";

?>


Here is a tutorial on multi-dimensional arrays


<?php
$customers = array(
array('first' => 'Bill', 'last' => 'Jones',
'age' => 24, 'state' => 'CA'),
array('first' => 'Mary', 'last' => 'Smith',
'age' => 32, 'state' => 'OH'),
array('first' => 'Joyce', 'last' => 'Johnson',
'age' => 21, 'state' => 'TX'),
);

$pet_breeds = array('dogs' => array('Poodle', 'Terrier', 'Dachshund'),
'birds' => array('Parrot', 'Canary'),
'fish' => array('Guppy', 'Tetra', 'Catfish', 'Angelfish')
);

printf("

The name of the second customer is %s %s.

\n",
$customers[1]['first'], $customers[1]['last']);

printf("

%s and %s

", $pet_breeds['dogs'][0], $pet_breeds['birds'][1]);


?>


The implode() function represents a handy way to output an entire indexed array in one go.


<?php
$languages = array('German', 'French', 'Spanish');

printf("

Languages: %s.

\n", implode(',',$languages));

?>


Here is another tutorial from the book PHP and MySQL Development


<?php
$pictures = array('tire.jpg', 'oil.jpg', 'spark_plug.jpg', 'door.jpg', 'steering_wheel.jpg', 'thermostat.jpg', 'wiper_blade.jpg', 'gasket.jpg', 'brake_pad.jpg');
shuffle($pictures);
?>

<html>
<head>
<title>Bob's Auto Parts - Customer Orders</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<div align="center">
<table width = 100%>
<tr>
<?php
for ($i = 0; $i < 3; $i++) {
echo "<td align=\"center\"><img src=\"";
echo $pictures[$i];
echo "\"/></td>";
}
?>
</tr>
</table>
</div>
</body>

Wednesday, February 9, 2011

Wednesday 2/9/11


<?php
class Employee
{
const CATEGORY_WORKER = 0;
const CATEGORY_SUPERVISOR = 1;
const CATEGORY_MANAGER = 2;

public static $jobTitles = array('regular worker', 'supervisor', 'manager');
public static $payRates = array(5, 8.25, 17.5);

public static function getCategoryInfo($cat)
{
printf("

A %s makes \$%.2f per hour.

\n",
self::$jobTitles[$cat],
self::$payRates[$cat]);
}

public static function calcGrossPay($hours, $cat)
{
return $hours * self::$payRates[$cat];
}
// instance variables

private $firstName;
private $lastName;
private $id;
private $category;

// employee constructor

public function __construct($fname, $lname, $id, $cat=self::CATEGORY_WORKER)
{
$this->firstName = $fname;
$this->lastName = $lname;
$this->id = $id;
$this->category = $cat;
}

public function getFirstName()
{
return $this->firstName;
}

public function getLastName()
{
return $this->lastName;
}

public function getId()
{
return $this->id;
}

public function getCategory()
{
return $this->category;
}

public function setFirstName($fname)
{
$this->firstName = $fname;
}

public function setLastName($lname)
{
$this->lastName = $lname;
}

public function setId($id)
{
$this->id = $id;
}

public function promote()
{
if($this->category < self::CATEGORY_MANAGER)
$this->category++;
}

public function demote()
{
if($this->category < self::CATEGORY_WORKER)
$this->catgory--;
}


public function display()
{
printF(
"

%s %s is Employee #%d, and is a %s making \$%.2f per hour

\n",
$this->getFirstName(),
$this->getLastName(),
$this->getId(),
self::$jobTitles[ $this->getCategory() ],
self::$payRates[ $this->getCategory() ]
);
}



} //end class employee

$bob = new Employee('Bob', 'Smith', 102, Employee::CATEGORY_SUPERVISOR);
$bob->display();
$bob->promote();
$bob->display();



?>

Tuesday, February 8, 2011

JavaScript


<Script type="text/javascript">
function randomColor() {

//get red
var r = randomVal(255).toString(16);
if (r.length<2) r="0" + r;

//get green
var g = randomVal(255).toString(16);
if (g.length<2) g="0" + g;

//get blue
var b = randomVal(255).toString(16);
if (b.length<2) b="0" + b;

return "#" + r + g + b;
}


function randomVal(val){
return Math.floor(Math.random() * val);
}



</Script>

Monday, February 7, 2011

Monday 2/7/2011


<?php
//Here we create and then call a simple function that outputs something.
function helloworld() {
echo "Hello World!
";
}
// We call it as easy as this:
helloworld();

//Creating and calling a function that accepts arguments is just as easy.
function saysomething($something){
echo $something . "
";
}
Saysomething("Hello World!"); //This would output "hello world!"

//and of course we can have our function return something as well.
function addvalues ($firstvalue, $secondvalue) {
return $firstvalue + $secondvalue;
}
$newvalue = addvalues (1,3);
echo $newvalue; //would echo "4".
?>


Here is another tutorial from PHP Recipes



<?php
//sample1_7.php

//Here is a variable. it is pretty easy to see it is a string.
$unknownvar = "Hello World!";
echo gettype ($unknownvar) . "
"; //will output string.
// the gettype is quite slow; the better way to do this is:
if (is_string ($unknownvar)){
//then do something with the variable.
echo "Is a string
";
}

?>


Here is another tutorial on casting.


<?php
//Let's say we start with a double value.
$mynumber = "1.03";
//and let's say we want an integer.
//we could do this:
$mynumber = settype ($mynumber, "integer");
echo $mynumber . "
"; //would output 1.
//but it is much better and looks far cleaner like this:
echo (int) $mynumber;

?>

Here is another tutorial.


<?php
// We are looking to receive a value from a "post" form before we search.
if (isset ($_POST['searchterm'])){
//then we would perform our search algorithm here.
}
else {
//or else, we generate an error.
echo "You must submit a search item. Please click the back button.";
}

?>


Here is another tutorial


<?php
error_reporting(E_ALL);
// we get the IP address of the current user.
$curip = $_SERVER['REMOTE_ADDR'];
//then we do a database query to see if this IP exists
$myarray = array();
if (!in_array ($curip, $myarray)) {
// then we insert the new IP address into the database.
echo "We insert the IP addy: " . $curip . " into the databse";
} else {
echo "The IP addy:" . $curip . " is already in the database.";
}
?>


Here is an introduction to object-oriented programming



<?php
class Bird
{
function __construct($name = 'no-name', $breed = 'breed unknown', $price=15)
{
$this->name = $name;
$this->breed = $breed;
$this->price = $price;
}
}

$aBird = new Bird();
$tweety = new Bird('Tweety', 'canary');

printf("

%s is a %s and costs \$%.2f.

\n", $aBird->name, $aBird->breed, $aBird->price);

printf("

%s is a %s.

\n", $tweety->name, $tweety->breed);
?>

Sunday, February 6, 2011

Sunday 2/6/2011


<?php
//set up a standard array.
$myarray = array("1", "2", "3");
// You can access values from the array as simply as this:
echo $myarray[0]; //would output '1'.
//Or with a for loop
for ($i = 0; $i < count ($myarray); $i++){
echo $myarray[$i] . "
";
}
// setting up an associative array is similarly easy.
$myassocarray = array("mykey" => 'myvalue', "another" => 'one');
//
while ($element = each ($myassocarray)) {
echo "Key - " . $element['key'] . " and Value - " . $element['value'] . "
";
}
?>

Friday, February 4, 2011

Friday Feb. 4 2010

Been working on a lot of projects, lots of snow.


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Replacement Insanity</title>
<script>
window.onload = function(){
// search for \d
var re = /\\d/;
var pattern = "\\d{4}";
var str = "I want 1111 to find 3334 certain 5343 things 8484";
var re2 = new RegExp(pattern, "g");
var str1 = str.replace(re2, "*****");
alert(str1);
var pattern2 = pattern.replace(re, "\\D");
var re3 = new RegExp(pattern2, "g");
var str2 = str.replace(re3, "****");
alert(str2);
}

</script>
</head>
<body>
<p>content</p>
</body>
</html>


Here is another program from teh Shelley Powers book



var dt = new Date();

// get month and increment
var mnth = dt.getUTCMonth();
mnth++;
alert(mnth);

var day = dt.getUTCDate();
if (day < 10) day="0" + day;
var yr = dt.getUTCFullYear();
alert(yr );

var hrs = dt.getUTCHours();
if (hrs < 10) hrs = "0" + hrs;
alert(hrs);

var min = dt.getUTCMinutes();
if (min < 10) min = "0" + min;
alert(min);

var secs = dt.getUTCSeconds();
if (secs < 10) secs = "0" + secs;
alert(secs);


var newDate = yr + "-" + mnth + "-" + day + "T" + hrs + ":" + min;

alert(newDate);




Here is another Shelley Powers tutorial. This one I could nto quite get to work - I got some IS0 8601 dates from wikipedia, and it was fine with teh date that did not have a time added, but for the date with time it kept saying that it was invalid.



<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Converting IS0 8601 Date</title>
<!-- note: this is from a tutorial by Shelley Powers, from her book "JavaScript Cookbook". I am using this for personal educational purposes only -->
<style type="text/css">
#dateSubmit
{
background-color: #ff0;
width:200px;
text-align: center;
border: 1px solid #ccc;
}
</style>
<script type = "text/javascript">
window.onload = function () {
document.getElementById("dateSubmit").onclick = convertDate;
}

function convertDate() {
var dtstr = document.getElementById("datestring").value;
var convdate = convertISO8601toDate(dtstr);
document.getElementById("result").innerHTML = convdate;
}

function convertISO8601toDate(dtstr) {

//replace anything but numbers by spaces
dtstr = dtstr.replace(/\D/g," ");

//trim any hanging white space
dtstr = dtstr.replace(/\s+$/,"");

// split on space
var dtcomps = dtstr.split(" ");

if (dtcomps.length < 3) return "invalid date";
// if time not provided, set to 0
if (dtcomps.length < 4) {
dtcomps[3] = 0;
dtcomps[4] = 0;
dtcomps[5] = 0;
}


//modify month between 1 based ISO 8601 and zero based date
dtcomps[1]--;

var convdt = new Date(Date.UTC(dtcomps[0], dtcomps[1], dtcomps[2], dtcomps[3], dtcomps[4], dtcomps[5]));

return convdt.toUTCString();
}
</script>
</head>
<body>
<form>
<p>Datestring in ISO 8601 format:
<input type="text" id="datestring" /></p>
</form>
<div id="dateSubmit">
<p>Convert Date
</p></div>
<div id="result"></div>

</body>
</html>


here is a timeout


window.onload=function() {
setTimeout("alert('timeout')",3000);
}


Here is the script and style from the next Shelley Powers tutorial.


<style>
#redbox
{
position: absolute;
left:100px;
top: 100px;
width:200px;
height:200px;
background-color:red;
}
</style>


<script type="text/javascript">
var intervalid=null;

window.onload=function() {
document.getElementById("redbox").onclick=stopStartElement;
}

function stopStartElement(){
if (intervalid == null) {
var x = 100;
intervalid = setInterval(function(){
x += 5;
var left = x + "px";
document.getElementById('redbox').style.left = left;
}, 100);
}
else {
clearInterval(intervalid);
intervalid = null;
}
}

</script>