Monday, January 31, 2011

Monday 1/31/2011


function setNumberOfSides() {
numSides = document.getElementById("numSides").value;
numSides = numSides + " sides per die";
var alertText = "";
var holderP = document.getElementById("numberOfSides");
alertText = document.createTextNode(numSides);

if (holderP.firstChild == null) {
holderP.appendChild(alertText);
}
else {
holderP.firstChild.nodeValue = numSides;
}
}

Here is something from the Shelley Powers book


<script type="text/javascript">
function init() {
var searchString = "Now is the time, this is the time";
var re = /t\w{2}e/g;
var replacement = searchString.replace(re, "place");
alert(replacement);
}
</script>

Here is another tutorial


<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Searching for Strings</title>
<style type="text/css">
#searchSubmit {
background-color:#ff0;
width: 200px;
text-align:center;
padding:10px;
border:2px inset #ccc;
}

.found
{
background-color: #ff0;
}

</style>
<script type="text/javascript">
window.onload=function() {
document.getElementById("searchSubmit").onclick=doSearch;
}

function doSearch() {
//get pattern
var pattern = document.getElementById("pattern").value;
var re = new RegExp(pattern, "g");

//get string
var searchString = document.getElementById("incoming").value;

// replace
var resultString = searchString.replace(re,"<span class='found'>$&</span>");

// insert into page
document.getElementById("searchResult").innerHTML = resultString;
}
</script>
</head>
<body>
<form id="textsearch">
<textarea id="incoming" cols="100" rows="10">

</textarea>
<P>
Search pattern: <input id="pattern" type="text" /></p>
</form>
<p id="searchSubmit">Search for a pattern


<div id="searchResult"></div>
</P>

</body>


Here is some more JavaScript


<script type="text/javascript">
var pieceOfHtml = "<p>This is a <span>paragraph</span

"
function convert(){
pieceOfHtml = pieceOfHtml.replace(/</g,"<");
pieceOfHtml = pieceOfHtml.replace(/>/g,">");
document.getElementById("searchResult").innerHTML = pieceOfHtml;
}
</script>

Sunday, January 30, 2011

Sunday, 1/30/11

Spent entirely too long on this:



function generate(){
var data = document.getElementById('inputText').value;
append(data);
}
function append(data){
var newP = document.createElement("p");
var mytext = document.createTextNode(data);
newP.appendChild(mytext)
document.getElementById("mydiv").appendChild(newP);
}

Friday, January 28, 2011

Monday 1/28/2011

"IN this simple example, you store each order record on a separate line in the file. Writing one record per line gives you a simple record separator in the newline character. Because newlines are invisible, you can represent them with the control sequence "\n".


<?php
// create short variable names
$tireqty = $_POST['tireqty'];
$oilqty = $_POST['oilqty'];
$sparkqty = $_POST['sparkqty'];
$address = $_POST['address'];
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
$date = date('H:i, jS F Y');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Bob's Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>

<?php
echo "<P>Order processed at " .date('H:i, js F Y')."</P>";
echo "<P>Your order is as follows: </p>";
$totalqty = 0;
$totalqty = $tireqty + $oilqty + $sparkqty;
echo "Items ordered " . $totalqty . "<br />";


// up to here is correct



if ($totalqty == 0) {
echo "You did not order anything on the previous page!<br/>";
} else {
if ($tireqty > 0) {
echo $tireqty . " tires<br />";
}
if ($oilqty > 0 ) {
echo $oilqty . " bottles of oil<br />";
}
if ($sparkqty > 0) {
echo $sparkqty . " spark plugs<br />";
}
}


// up to here is correct




$totalamount = 0.00;

define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4);

$totalmount = number_format($totalamount, 2, '.', ' ');

echo "<P>Total of order is $" . $totalamount . "</p>";
echo "<P>Address to ship to is " . $address . "</p>";

$outputstring = $date . "\t" . $tireqty . " tires \t" . $oilqty . " oil\t" . $sparkqty . " spark plugs\t\$" . $totalamount . "\t" . $address . "\n";

// open file for appending
@ $fp = fopen("C:\inetpub\wwwroot\Practice\Book\orders.txt", 'ab');

flock($fp, LOCK_EX);

if (!$fp) {
echo "<p><strong>Your order could not be processed at this time. Please try again later.</strong></p></body></html>";
exit;
}

fwrite($fp, $outputstring, strlen($outputstring));
flock($fp, LOCK_UN);
fclose($fp);

echo "

Order written.

";

?>

</body>

Wednesday, January 26, 2011


<!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>canHaveChildren Property</title>
<script type="text/javascript">
function colorAll() {
var elems = document.getElementsByTagName("*");
for (var i = 0; i < elems.length; i++) {
elems[i].style.color = "red";
}
}

</script>
</head>
<body>
<h1>Color All</h1>
<hr />
<form name="input">
<input type="button" value="Color All Elements" onclick="colorAll()" /><br />
<input type="button" value="Reset" onclick="history.go(0)" />

</form>
<br />
<hr />
<form name="output">
<input type="checkbox" checked="checked" />Your Basic checkbox
</form>
<table id="myTable" cellpadding="10" border="2">
<tr>
<th>Quantity</th>
<th>Description</th>
<th>Price</th>
</tr>
<tbody>
<tr>
<td width="100">4</td>
<td>Primary Widget</td>
<td>$14.96</td>
</tr>
<tr>
<td>10</td>
<td>Secondary Widget</td>
<td>$114.96</td>
</tr>
</tbody>
</table>
</body>
</html>

Tuesday, January 25, 2011


<html>
<head>
<title>A Simple Page </title>
<script type="text/javascript">
function modify() {
var newElem = document.createElement("p");
newElem.id = "newP";
var newText = document.createTextNode("This is the second paragraph.");
newElem.appendChild(newText);
document.body.appendChild(newElem);
document.getElementById('emphasis1').childNodes[0].nodeValue = 'first';
}

function addSomething() {
var newEdition = document.createElement("div");
newEdition.id ="newDiv";
var addText = document.createTextNode("Here is another additional text.");
newEdition.appendChild(addText);
document.body.appendChild(newEdition);
}
</script>
</head>
<body>
<button onclick="modify()">Add/Replace Text
<button onclick="addSomething()">Add Something else
<

<p id="paragraph1">This is the <em id="emphasis1">one and only </em> paragraph on the page. </p>


</body>
</html>


Advanced XHTML is a time-eater. Learning jQuery looks interesting though.

Sunday, January 23, 2011

Sunday 1/23/11


<?Php
echo "

Order processed.

";
echo "order processed at " . date('H:i, jS F Y');
echo "

";
// create short variable names
$tireqty = $_POST['tireqty'];
$oilqty = $_POST['oilqty'];
$sparkqty = $_POST['sparkqty'];
echo "

Your order is as follows:

";
echo $tireqty . " tires
";
echo $oilqty . " bottles of oil
";
echo $sparkqty . " spark plugs
";

$totalqty = 0;
$totalqty = $tireqty + $oilqty + $sparkqty;
echo "

";

if ($totalqty == 0) {
echo '<p style="color:red">';
echo 'You did not order anything on the previous page!';
echo '

';
}

echo "Items ordered: " . $totalqty . "
";
$totalamount = 0.00;

define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4);


$totalamount = $tireqty * TIREPRICE
+ $oilqty * OILPRICE
+ $sparkqty * SPARKPRICE;

echo "Subtotal: $" . number_format($totalamount, 2) . "
";

$taxrate = 0.10; // local sales tax is 10%
$totalamount = $totalamount * (1 + $taxrate);
echo "Total including tax: $" . number_format($totalamount, 2) . "
";

?>


Here is another tutorial

<?php
$distance = 50;
while ($distance <= 250) {
echo "<tr>";
echo $distance . "</td>";
echo "<td align = \"right\">" . ($distance/10) . "</td></tr>";
$distance += 50;
}
?>

Friday, January 21, 2011

Friday 1/21/11


<?php
echo fix_names("William", "henry", "gatES");

function fix_names($n1, $n2, $n3)
{
$n1 = ucfirst(strtolower($n1));
$n2 = ucfirst(strtolower($n2));
$n3 = ucfirst(strtolower($n3));
return $n1 . " " . $n2 . " " . $n3;
}
?>


Here is more PHP code from the book by Robin Nixon "Learning PHP, MySQL, and JavaScript"


<?php
$names = fix_names("WILLIAM", "henry", "gatES");
echo $names[0] . " " . $names[1] . " " . $names[2];

function fix_names($n1, $n2, $n3)
{
$n1 = ucfirst(strtolower($n1));
$n2 = ucfirst(strtolower($n2));
$n3 = ucfirst(strtolower($n3));
return array($n1, $n2, $n3);
}


?>


Here is another exercise from the Robin Nixon book


<?php
echo "Returning values from a function by reference";
echo "
";

$a1 = "William";
$a2 = "henry";
$a3 = "gatES";

echo $a1 . " " . $a2 . " " . $a3 . "
";
fix_names($a1, $a2, $a3);
echo $a1 . " " . $a2 . " " . $a3;

function fix_names(&$n1, &$n2, &$n3)
{
$n1 = ucfirst(strtolower($n1));
$n2 = ucfirst(strtolower($n2));
$n3 = ucfirst(strtolower($n3));
}

?>


Here is 5-9


<?php

if (function_exists("array_combine"))
{
echo "Function exists";
}
else
{
echo "Function does not exist - better write our own";
}

?>


Example 5-11



<?php
$object = new User;
print_r($object); echo"<br />";
$object->name = "Joe";
$object->password = "mypass";
print_r($object);
echo "
";

$object->save_user();

class User
{
public $name, $password;
function save_user()
{
echo "Save User code goes here";
}
}
?>



Here is another quick tutorial


<?php
$object1 = new User();
$object1->name = "Alice";
$object2 = $object1;
$object2->name = "Amy";
echo "object1 name = " . $object1->name . "
";
echo "object2 name = " . $object2->name;

class User
{
public $name;
}
?>


Here is another tutorial by Robin Nixon


<html>

<body>
<?php
echo "Inhereting and extending a class";
echo "

";
$object = new Subscriber;
$object->name = "Fred";
$object->password = "pword";
$object->phone = "012 345 6789";
$object->email = "fred@bloggs.com";

$object->display();


class User
{
public $name, $password;
function save_user()
{
echo "Save User code goes here";
}
}

class Subscriber extends User
{
public $phone, $email;

function display()
{
echo "Name: " . $this->name . "
";
echo "Pass: " . $this->password . "
";
echo "Phone: " . $this->phone . "
";
echo "Email: " . $this->email;
}

}

?>
</body>
</html>


Here is the final PHP tutorial for the day


<??php
$object = new Son;
$object->test();
$object->test2();

class Dad
{
function test()
{
echo "[Class Dad] I am your Father
";
}
}

class Son extends Dad
{
function test()
{
echo "[Class Son] I am luke
";
}

function test2()
{
parent::test();
}
}

?>


Here is a JavaScript tutorial from the Shelley Powers book. This is not all of it, I am not posting the HTML and CSS as it is not really relevant.


<script type="text/javascript">
//<![CDATA]

window.onload=function() {
document.getElementById("searchSubmit").onclick=doSearch;
}

function doSearch()

//only problem is that it is case-dependent.
{
// get pattern
var pattern = document.getElementById("pattern").value;
var regExpression = new RegExp(pattern, "g");


//get string
var searchString = document.getElementById("incoming").value;
var matchArray;
var resultString = "
";
var first=0; var last=0;

//find each match
while ((matchArray = regExpression.exec(searchString)) != null) {
last = matchArray.index;
// get all of string up to match, concatenate
resultString += searchString.substring(first, last);

// add matched, with class
resultString += "" + matchArray[0] + "";
first = regExpression.lastIndex;
}

// finish off string
resultString += searchString.substring(first, searchString.length);
resultString += "
";

// insert into page
document.getElementById("searchResult").innerHTML = resultString;
}



</script>


I have to admit, I got all of it typed in, got it to work, renamed a few of the variables even (I don't like short variable names) but...still not completely at ease with it, regular expressions are a bit complicated, I think.

Here is the code from Lab 4 of my JavaScript class




<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>



<!-- I decided not to embed the style sheet but rather link to it -->
<link rel="stylesheet" type="text/css" href="temperatureStyles.css" media="screen" />
<script type="text/javascript">
var convertToCelsius = false;
var convertToFaranheit = false;

// This function sets the conversion to Farenheit as well as creates a subtle visual effect by turning
// the Farenheit text next to the radio button blue
function blueF(){
document.getElementById("spanF").className = "blueLine";
document.getElementById("spanC").className = "blackLine";
convertToFahrenheit = true;
convertToCelsius = false;
}

//note to self: Fahrenheit spelled F a h r e n h e i t
function blueC(){
document.getElementById("spanC").className = "blueLine";
document.getElementById("spanF").className = "blackLine";
convertToFahrenheit = false;
convertToCelsius = true;
}


// This function checks to see that a radio button has been selected, that the text field is not blank, and that the text blank
// contains a number
function validateEntry(value){

if (convertToCelsius == false && convertToFahrenheit == false)
{
alert("Please select Faranheit or Celsius");
return false;
}
else if (value == "")
{
alert("Please enter a value");
return false;
}
else if (isNaN(value) == true)
{
alert("Please enter a numeric value");
return false;
}
else
{
return true;
}
}


// This function will branch into two different options using a conditional operator (provided that the data entered is valid)
function convertIt(){


var entryData = document.getElementById("temp").value;

// use a seperate function to validate the data
if (validateEntry(entryData))
{
document.getElementById("temp").value = "";
// I finally dared to write a conditional operator
convertToCelsius==true ? convertFromFahrenheit(entryData) : convertFromCelsius(entryData);
}
else
{
document.getElementById('results').innerHTML = "Please make sure your entry is correct.";
}

}


function convertFromCelsius(entryData) {
var conversionData = entryData
conversionData = ((entryData * 1.8) + 32);
document.getElementById('results').innerHTML = "The temperature is " + conversionData + " degrees Fahrenheit";
document.getElementById('results').innerHTML += "<P></P>The temperature you converted <i>from</i> was " + entryData + " degrees Celsius";
}

function convertFromFahrenheit(entryData)
{
var conversionData = entryData
conversionData = ((entryData - 32) * .55);
document.getElementById('results').innerHTML = "The temperature is " + conversionData + " degrees Celsius";
document.getElementById('results').innerHTML += "

The temperature you converted from was " + entryData + " degrees Fahrenheit";
}





</script>

</head>
<body>

<!-- This DIV will hold the site in the center of the screen. -->
<div id="main">


<!-- This div will float left and contain the textboxes for entering the data -->
<!-- We are about to learn about jQuery and rounded corners for our advanced XHTML class -->
<!-- but I figured I better not mess around with that for now -->

<div id="left">
<h1 class = "header">Enter Temperature Here</h1>
<form id="entryForm">
Temperature: <input type="text" id="temp"></input>
<BR>
Convert to:
<br>
<span id="spanF">Fahrenheit </span><input type="radio" name="rSelect" id="radio-1" value="1" onclick="blueF()"></input>

<span id="spanC">Celsius </span><input type="radio" name="rSelect" id="radio-2" value="1" onclick="blueC()"></input>
</form>
<input type="button" id="btnInput" value="Convert" onclick="convertIt()"></input>
</div>



<!-- This div will float right and present the output for data -->
<div id="right">
<h1 class = "header">View Converted Temperature Here</h1>
<div id="results">

</div>
</div>



</div>
</body>
</html>

Thursday, January 20, 2011

Thursday, January 20th 2011


<html>
<head>
<title>Image Object</title>
<script type="text/javascript">
// initialize empty array
var imageLibrary = new Array();
// pre-cache four images
imageLibrary["image1"] = new Image(350,350);
imageLibrary["image1"].src = "images/desk1.jpg";
imageLibrary["image2"] = new Image(350,350);
imageLibrary["image2"].src = "images/desk2.jpg";
imageLibrary["image3"] = new Image(350,350);
imageLibrary["image3"].src = "images/desk3.jpg";
imageLibrary["image4"] = new Image(350, 350);
imageLibrary["image4"].src = "images/desk4.jpg";

// load an image chose from seelct list
function loadCached(list) {
var img = list.options[list.selectedIndex].value;
document.thumbnail.src = imageLibrary[img].src;
}
</script>
</head>
<body>
<h2>Image Object</h2>
<img src="images/desk1.jpg" name="thumbnail" height="350" width="350">
<form>
<select name="cached" onchange="loadCached(this)">
<option value="image1">Bands
<option value="image2">Clips
<option value="image3">Lamp
<option value="image4">Erasers
</select>
</form>

</body>

</html>


Here is another JavaScript program from the JavaScript Bible


<!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>12-2 Image Rollovers</title>
<script type="text/javascript">
if (document.images) {
//precache all 'off' button images
var offImgArray = new Array();
offImgArray["play"] = new Image(175, 175);
offImgArray["stop"] = new Image(175, 175);
offImgArray["pause"] = new Image(175, 175);
offImgArray["rewind"] = new Image(175, 175);

// off image array -- set 'off' image path for each button
offImgArray["play"].src = "images/play.png";
offImgArray["stop"].src = "images/stop.png";
offImgArray["pause"].src = "images/pause.png";
offImgArray["rewind"].src = "images/rewind.png";

// precache all 'on' button images
var onImgArray = new Array();
onImgArray["play"] = new Image(175, 175);
onImgArray["stop"] = new Image(175, 175);
onImgArray["pause"] = new Image(175, 175);
onImgArray["rewind"] = new Image(175, 175);

//on image array --- set 'on' image path for each button
onImgArray["play"].src = "images/play_onhover.png";
onImgArray["stop"].src = "images/stop_onhover.png";
onImgArray["pause"].src = "images/pause_onhover.png";
onImgArray["rewind"].src = "images/rewind_onhover.png";
}

// functions that swap images & status bar
function imageOn(imgName) {
if (document.images){
document.images[imgName].src = onImgArray[imgName].src;
}
}

//
function imageOff(imgName){
if (document.images) {
document.images[imgName].src = offImgArray[imgName].src;
}
}

function setMsg(msg) {
window.status = msg;
return true;
}
//controller functions

function playIt(){
}

function stopIt(){
}

function pauseIt(){
}

function rewindIt(){
}
</script>
</head>
<body>
<center>
<form>
<a href="javascript:playIt()" onmouseover = "imageOn('play'); return setMsg('Play the selected tune')" onmouseout="imageOff('play'); return setMsg('')">
<img src="images/play.png" name="play" height="175" width="175" border="1">
</a>
<a href="javascript:playIt()" onmouseover = "imageOn('stop'); return setMsg('Stop the playing tune')" onmouseout="imageOff('stop'); return setMsg('')">
<img src="images/stop.png" name="stop" height="175" width="175" border="1">
</a>
<a href="javascript:playIt()" onmouseover = "imageOn('pause'); return setMsg('Pause the tune')" onmouseout="imageOff('pause'); return setMsg('')">
<img src="images/pause.png" name="pause" height="175" width="175" border="1"></img>
</a>
<a href="javascript:playIt()" onmouseover = "imageOn('rewind'); return setMsg('Rewind the tune')" onmouseout="imageOff('rewind'); return setMsg('')">
<img src="images/rewind.png" name="rewind" height="175" width="175" border="1"></img>
</a>

</form>
</center>
</body>
</html>

Tuesday, January 18, 2011

Tuesday, January 18th

Here is the javaScript from a program I am writing from a Lynda.Com series of tutorials.


window.onload = newCard;

function newCard() {
if (document.getElementById){
for (var i = 0; i < 24; i++) {
setSquare(i);
}
}
else
alert("You might want to upgrade your browser.")
}

function setSquare(thisSquare) {
var currentSquare = "square" + thisSquare;
var colPlace = new Array(0,1,2,3,4, 0,1,2,3,4, 0,1,3,4, 0,1,2,3,4, 0,1,2,3,4);
var newNum = (colPlace[thisSquare] * 15) + getNewNum() + 1;
document.getElementById(currentSquare).innerHTML = newNum;
}

function getNewNum(){
return Math.floor(Math.random() * 15)
}


Here is the HTML for onmouseover and onmouseout


<body>
<a href="Lab02.html" onmouseover="document.arrow.src = 'images/arrow_on.png'"
onmouseout = "document.arrow.src='images/arrow_off.png'"><img src="images/arrow_off.png" name="arrow" alt="arrow" /></a>
</body>

Monday, January 17, 2011

Here is code from Tim Patrick's library program that I am working through


Public Function GetSubStr(ByVal origString As String, _
ByVal delim As String, ByVal whichField As Integer) _
As String
' ---- Extracts a delimited string from another
' larger string
Dim stringParts() As String

' --- Handle some errors.
If (whichField < 0) Then Return ""
If (Len(origString) < 1) Then Return ""
If (Len(delim) = 0) Then Return ""

' ----- Break the string up into delimited parts
stringParts = Split(origString, delim)
' ---- See whether the part we want exists and returns it.
If (whichField > UBound(stringParts) + 1) Then Return "" _
Else Return stringParts(whichField - 1)
End Function


Here is a PHP program from lynda.com


<?php
$array1 = array(3,4,8, 15, 16, 22, 25, 42, 56, 78);
?>

Count: <?php echo count($array1); ?> <br/>
Max Value: <br/>
Min Value: <br/>
<P></p>
Sort: <?php sort($array1); print_r($array1); ?> <br/>
Reverse Sort: <?php rsort($array1); print_r($array1); ?>


Here is some JavaScript I took from Lynda.Com

window.onload = initAll();

function initAll() {
switch(navigator.platorm){
case "Win32":
alert("You're running Windows");
break;
case "MacPPC":
alert("You have a PowerPC-based Mac");
break;
case "MacIntel":
alert("You have an Intel-based Mac");
break;
default:
alert("You have a " + navigator.platform);
}
}

Sunday, January 16, 2011

Sunday 1/16/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>Linda 2002 Practice</title>

<script type="text/javascript">
var window1
var window2

function makeWindows()
{
window1 = window.open("","", "Height=300, width=300");
window2 = window.open("","", "Height=300, width=300");
}

function writeData()
{
window1.document.write("<h1>Greetings</h1>, my name is Window one.");
window2.document.write("Greetings, <h1>my</h1> name is Window two.");
}

makeWindows();

if(window.confirm("Add data to Windows?"))
{
writeData();
}


</script>
</head>
<body>
</body>
</html>


LAB #3 JavaScript


<!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>Untitled Document</title>


<style type="text/css" media="all">
.focused {
color:dark grey;
font-family:arial,san-serif;
padding:7px;
border:1px solid black;
line-height:3;
width:400px;
height:300px;
}

.unFocused {
color:grey;
font-family:arial,san-serif;
padding:7px;
border:1px solid silver;
line-height:3;
width:400px;
height:300px;
}

table {margin-left:auto;
margin-right:auto;}



</style>

<script style="text/javascript">
var newPerson;

function createPerson(){
// need to use the keyword this, this used inside a function makes it a constructor function
this.firstName = "";
this.lastName = "";
this.number = "";
this.areaCode = "";
}

function assignValues(){
alert("hello! function");
newPerson = new createPerson();
newPerson.firstName = document.getElementById('firstName').value;
newPerson.lastName = document.getElementById('lastName').value;
newPerson.areaCode = document.getElementById('areaCode').value;
newPerson.number = document.getElementById('number').value;
window.alert(newPerson.firstName);
displayValues();
}


function displayValues(){
// var results = newPerson.lastName + ", " + newPerson.firstName + ", " + newPerson.areaCode + " " + newPerson.number;
var results = generateResults()
document.getElementById('displayResults').innerHTML = results;
document.getElementById("entryForm").className = "unFocused";
document.getElementById("displayResults").className="focused";
}

function generateResults(){
var genResults;
var fullName;
var fullNumber;

if (newPerson.firstName != "" && newPerson.lastName != "")
fullName = newPerson.lastName + ", " + newPerson.firstName + " ";
else if (newPerson.firstName != "" && newPerson.lastName == "")
fullName = newPerson.firstName + " ";
else if (newPerson.firstName == "" && newPerson.lastName != "")
fullName = newPerson.lastName + " ";
else
fullName = "unknown";

if (newPerson.areaCode != "" && newPerson.number != "")
fullNumber = "(" + newPerson.areaCode + ") " + newPerson.number;
else
fullNumber = "";

genResults = fullName + fullNumber;
return genResults;
}

function focusOnForm(){
document.getElementById("entryForm").className = "focused";
document.getElementById("displayResults").className="unFocused";
}

function clearValues() {
document.getElementById("firstName").value = "";
document.getElementById("lastName").value = "";
document.getElementById('areaCode').value = "";
document.getElementById('number').value = "";
}


</script>
</head>


<body onload="focusOnForm()">






<table>
<tr colspan="2">
<td>
<form id="entryForm">
First Name: <input type="text" id="firstName" onclick="focusOnForm()"></input>
<BR/>
Last Name: <input type="text" id="lastName" onclick="focusOnForm()"></input>


Area Code: <input type="text" id="areaCode" onclick="focusOnForm()"></input>


Phone Number: <input type="text" id="number" onclick="focusOnForm()"></input>
<BR/>
<input type="button" value="submit" onclick="assignValues()"></input> </input>
</form>
</td>

<td>
<div id="displayResults">

</div>
</td>
</tr>

</table>


</body>
</html>

Friday, January 14, 2011

Friday 1/14/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>LINDA practice</title>
<!-- From LINDA.COM -->
<script type="text/javascript">

function linkObject(title, url, description)
{
this.title = title;
this.url = url;
this.description = description;
this.displayLink = displayLink;
}

function displayLink()
{
document.write("
" + this.title + "
");
document.write(this.description);
}

samplelink2 = new linkObject();
samplelink2.title = "Lynda.Com";
samplelink2.url = "http://www.lynda.com/";
samplelink2.displayLink()



</script>
</head>
<body>
</body>
</html>
</title>

Thursday, January 13, 2011

Thursday, 1/13/11


Public Class Form1
'This has been slightly adapted by me From Visual Basic Cookbook 2005
Dim WithEvents DragBar As New PictureBox
Const HT_Caption As Integer = &H2
Const WM_NCLBUTTONDOWN As Integer = &HA1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.FormBorderStyle = 0
DragBar.BackColor = Color.Blue
DragBar.Location = New Point(50, 50)
DragBar.Width = (Me.Width * 0.9)

Me.Controls.Add(DragBar)
End Sub

Private Sub DragBar_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles DragBar.MouseDown
If (e.Button = Windows.Forms.MouseButtons.Left) Then
'---- Don't hold on to the mouse locally
DragBar.Capture = False

'----Trick the form into thinking it received a title click
Me.WndProc(Message.Create(Me.Handle, WM_NCLBUTTONDOWN, _
CType(HT_Caption, IntPtr), IntPtr.Zero))
'All of the activity within a Windows form happens through messages being processed through a Windows procedure, or WndProc. This method is as old as windows
End If
End Sub
End Class


Here is a javascript tutorial it took my a while to work on:


<!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>Untitled Document</title>
<style type="text/css" media = "screen">


</style>
<script type="text/javaScript" charset="utf-8">
function Square( side, color ){
this.side = side;
this.color = color;
}


</script>
</head>
<body>
<script type="text/javaScript" charset="utf-8">
var sq01 = new Square(140, "Green");
document.writeln( sq01.color );
document.writeln( '<div style="background-color: blue; height:50px; width:50px;"></div>' );
document.writeln( '<BR>');
document.writeln( '<div style="background-color: ' + sq01.color + '; height: 60px; width: 60px;"></div>' );
document.writeln( '<br>');
document.writeln( '<div style="background-color: ' + sq01.color + '; height: ' + sq01.side + 'px; width: ' + sq01.side + 'px; "></div>' );
</script>
</body>
</html>

Thursday, 1/13/11

Public Class Form1
'This has been slightly adapted by me From Visual Basic Cookbook 2005
Dim WithEvents DragBar As New PictureBox
Const HT_Caption As Integer = &H2
Const WM_NCLBUTTONDOWN As Integer = &HA1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.FormBorderStyle = 0
DragBar.BackColor = Color.Blue
DragBar.Location = New Point(50, 50)
DragBar.Width = (Me.Width * 0.9)

Me.Controls.Add(DragBar)
End Sub

Private Sub DragBar_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles DragBar.MouseDown
If (e.Button = Windows.Forms.MouseButtons.Left) Then
'---- Don't hold on to the mouse locally
DragBar.Capture = False

'----Trick the form into thinking it received a title click
Me.WndProc(Message.Create(Me.Handle, WM_NCLBUTTONDOWN, _
CType(HT_Caption, IntPtr), IntPtr.Zero))
'All of the activity within a Windows form happens through messages being processed through a Windows procedure, or WndProc. This method is as old as windows
End If
End Sub
End Class

Tuesday, January 11, 2011

Tuesday 1/11/10


<?php
function strcat($left, $right) {
return $left . $right;
}

$first = "This is a ";
$second = " complete sentence!";
echo strcat($first, $second);
?>


Here is another tutorial

<html>
<body>
<?php
$d = date("D");
if ($d == "Fri")
echo "Have a nice weekend!";
elseif ($d == "Sun")
echo "Have a nice Sunday!";
else
echo "Have a nice day!";
?>
</body>
</html>

Here is the last tutorial of the day on PHP, next I will work on JavaScript


<html>
<head>
<title>String Functions</string>
</head>
<body>
<?php
$firstString = "The quick brown fox ";
$secondString = " jumped over the lazy dog.";
?>
<?php
$thirdString = $firstString;
$thirdString .= $secondString;
echo $thirdString;
?>
<br />
Length: <?php echo strlen($thirdString); ?><br />
Find: <?php echo strstr($thirdString, "brown"); ?><br />
Replace by String: <?php echo str_replace("quick", "super-fast", $thirdString); ?>


</body>
</html>


Here is a JavaScript Tutorial



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function showStrings()
{
var cookbookString = new Array();

cookbookString[0] = "Joe's Cooking Book";
cookbookString[1] = "Sam's Cookbook";
cookbookString[2] = "JavaScript Cookbook";
cookbookString[3] = "JavaScript cookbook";
cookbookString[4] = "Cooking with Gas";

// search pattern

// When creating the regular expression, use the ignore case flag (i)
var pattern = /Cook.*Book/i;

for (var i = 0; i < cookbookString.length; i++)
{
alert(cookbookString[i] + " " + pattern.test(cookbookString[i],i));
}
}
</script>
</head>
<body onload="showStrings()">
</body>
</html>


Here is another tutorial, dealing with social security numbers



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>2.3 Validating a Social Security Number</title>
<script type="text/javascript">
// The numbers in a Social Security number can be matched with the digit special character (\d)
function checkNumber()
{
var ssn = document.getElementById("pattern").value;
var pattern = /^\d{3}-\d{2}-\d{4}$/;
if (ssn.match(pattern))
alert("OK");
else
alert("Not OK");
}
</script>
</head>
<body>
<form>
<input type="text" id="pattern">
<BR>
<input type="submit" id="submitButton" onclick="checkNumber()"></input>
</form>
</body>
</html>

Monday, January 10, 2011

Monday 1/10/11

First PHP class today

http://localhost/

FIRST PHP TUTORIAL, from the book Programming PHP, 2nd Edition by Peter MacIntyre



<html>
<head>
<title>Personalized Hello World!</title>
</head>
<body>

<?php if(!empty($_POST['name'])) {
echo "Greetings, {$_POST['name']}, and welcome.";
} ?>

<form action="" method="post">
Enter your name: <input type="text" name="name" />
<input type="submit" />
</form>

</body>
</html>


Here is something short that I wrote myself involving both CSS and JavaScript.


<!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>Untitled Document</title>
<LINK href="exampleCSS.css" rel="stylesheet" type="text/css">
<script style="text/javascript">
function changeColor()
{
document.getElementById('bigParagraph').className = "isBlue";
}
</script>
</head>
<body>
<p id="bigParagraph">Here is some data. Information information information</p>
</body>
<input type="button" value = "change color" onclick="changeColor()">
</html>

Thursday, January 6, 2011

I have no idea how I managed to write this thing and actually get it to work:


<!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>Lab 002</title>
<script type="text/javascript">
// I wrote one function to get the values for both sides of the rectangle
function getValue(numNumber){

var stringValue = "";
if (numNumber == 1) {
stringValue = "the length of the rectangle";
}
else
if (numNumber == 2) {
stringValue = "the width of the rectangle";
}

var integerHolder = 0;
while (integerHolder < 1) {
var valueHolder = prompt("Please enter the value for " + stringValue);
if (valueHolder == "") {
alert("Value was empty");
}
else
if (isNaN(valueHolder)) {
alert("Please enter a number");
}
else {
integerHolder++;
}
return valueHolder;
}
}



var xValue = getValue(1);
var yValue = getValue(2);

var total = parseInt(xValue) * parseInt(yValue);
alert("The area of the rectangle is " + total);



</script>
</head>
<body>

</body>
</html>

Wednesday, January 5, 2011

Wednesday, 1/05/11


<head>
<title>Check 1.1</title>
<script type="text/javascript">
window.onload = function(){
var keywordList = prompt("Enter keywords, seperated by commas", "");

var arrayList = keywordList.split(",");

var resultString = "";
for (var i = 0; i < arrayList.length; i++) {
resultString+="Keyword: " + arrayList[i] +
;
}

var blk = document.getElementById("result");
blk.innerHTML = resultString;
}
</script>
</head>
<body>
<div id="result">

</div>

</body>


"You can also use a regular expression as the parameter to split, thought this can be a bit tricky." - Shelley Powers

After much fussing and fighting, I got this to work:


<html>
<head>
<title>1.9 Processing individual lines of a text area</title>
<script type="text/javascript">

function ClipBoard()
{
alert("Hello!");
}

function doMethod()
{
alert("Processing!");
var txtBox = document.getElementById("test");
var lines = txtBox.value.split("\n");

var resultString ="

";
resultString += "Result: ";
for (var i =0; i < lines.length; i++)
{
resultString += lines[i] + "
";
}

var blk = document.getElementById("result");
blk.innerHTML = resultString;
}

</script>
</head>
<body>
<form>
<textarea id="test" onClick="ClipBoard();" rows="25" columns="25">

</textarea>
<br>
<br>
<input type="submit" id="submitButton" onClick="doMethod();" value="submit">
</form>
<p></p>

<textbox id="result">

</textbox>
</body>
</html>



my final tutorial for the day is from Michael Halvorston, on printing using Visual Basic


Imports System.Drawing.Printing

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Print using an error handler to catch problems
Try
'Declare PrintDoc variable of type PrintDocument
Dim PrintDoc As New PrintDocument
AddHandler PrintDoc.PrintPage, AddressOf Me.PrintText
PrintDoc.Print() 'print text
Catch ex As Exception
MessageBox.Show("Sorry--there is a problem printing", _
ex.ToString())
End Try
End Sub



Private Sub PrintText(ByVal Sender As Object, _
ByVal ev As PrintPageEventArgs)
'Use DrawString to create text in a Graphics object
ev.Graphics.DrawString(TextBox1.Text, New Font("Arial", _
11, FontStyle.Regular), Brushes.Black, 120, 120)
'specify that this is the last page to print
ev.HasMorePages = False
End Sub
End Class

Tuesday, January 4, 2011

Tueday 1/04/11


Module Module1

Sub Main()
Dim obj1 As New yourClass("AAA")
Dim obj2 As New yourClass("BBB")

obj1.displayMessage()
Console.WriteLine(obj2.yourName)

Console.ReadLine()
End Sub

End Module

Public Class yourClass
Private yourNameValue As String

'constructor initializes course name with String supplied as an argument

Public Sub New(ByVal Name As String)
yourNameValue = Name 'initialize yourNameValue via property
End Sub

'property yourName
Public Property yourName() As String
Get 'retrieve yourNameValue
Return yourNameValue
End Get
Set(ByVal value As String)
yourNameValue = value 'store the course name in the object
End Set
End Property 'set

Public Sub displayMessage()
Console.WriteLine("Welcome " & yourName & "!")
End Sub

End Class


Here is a tutorial on cycling through a forms controls


Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles actRed.Click
UpdateAllLabels(Color.Red)
End Sub


Private Sub updateAllLabels(ByVal withColor As Drawing.Color)
'scan all controls as control in me.controls
For Each scanControls As Control In Me.Controls
If (TypeOf scanControls Is Label) Then
scanControls.BackColor = withColor
End If
Next scanControls

End Sub

Private Sub actNormal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles actNormal.Click
updateAllLabels(SystemColors.Control)
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
End Class


Here is a tutorial for sharing event-handler logic among many controls


Private Sub MultipleEvents(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
TextBox1.Enter, TextBox2.Enter, TextBox3.Enter, _
TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged
' --- Report the current status of this field
Dim activeControl As TextBox
activeControl = CType(sender, TextBox)
ShowInfo.Text = "Field #" & _
Microsoft.VisualBasic.Right(activeControl.Name, 1) & _
", " & activeControl.Text.Length & " character(s)"

End Sub


Here is another tutorial


Public Class Form1
Public WithEvents ColorList As ListBox
Dim listBoxMaker As bBuilder

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
listBoxMaker = New bBuilder
listBoxMaker.position()
listBoxMaker.add()
listBoxMaker.giveName("listbox1")
ColorList = Me.Controls("listbox1")

Me.Controls.Add(ColorList)
ColorList.Items.Add("Red")
ColorList.items.add("Orange")
ColorList.Items.Add("Yellow")
ColorList.Items.Add("Green")
ColorList.Items.add("Blue")
ColorList.Items.add("Indigo")
ColorList.Items.Add("Violet")
End Sub

Private Sub form1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs)

' --- draw an ellipse on the form.
e.Graphics.DrawEllipse(Pens.Black, 10, 10, _
Me.ClientRectangle.Width - 20, _
Me.ClientRectangle.Height - 20)
End Sub

Private Sub XButton_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles xbutton.paint
' ---- draw a big x in a rectangle on the button surface
Dim usePen As Pen

'Provide a neutral background
e.Graphics.Clear(SystemColors.Control)

'----- draw the outline box.
usePen = New Pen(SystemColors.ControlText, 3)
e.Graphics.DrawRectangle(usePen, XButton.ClientRectangle)

'---Draw the
e.Graphics.DrawLine(usePen, 0, 0, _
XButton.Width, XButton.Height)
e.Graphics.DrawLine(usePen, 0, _
XButton.Height, XButton.Width, 0)
usePen.Dispose()
End Sub

Public Sub ColorList_DrawItem(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DrawItemEventArgs) _
Handles ColorList.DrawItem
' --- Draw the color instead of the text
' ---- personal note: added withEvents to the colorList listbox

Dim useBrush As Brush


'--- check for a nonselected item
If (e.Index = -1) Then Return

'--- Set the neutral background
e.DrawBackground()

' ----- fill in the color
useBrush = New SolidBrush(Color.FromName(CStr(ColorList.Items(e.Index))))
e.Graphics.FillRectangle(useBrush, _
e.Bounds.Left + 2, e.Bounds.Top + 2, _
e.Bounds.Width - 4, e.Bounds.Height - 4)
useBrush.Dispose()

'---- Surround the color with a black rectangle.
e.Graphics.DrawRectangle(Pens.Black, _
e.Bounds.Left + 2, e.Bounds.Top + 2, _
e.Bounds.Width - 4, e.Bounds.Height - 4)

'show the item selected if needed
e.DrawFocusRectangle()
End Sub


Private Sub XButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles XButton.Click
MsgBox("Button clicked.")
End Sub
End Class

Monday, January 3, 2011

Monday 1/03/11


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "Convert Temperatures"

End Sub

Private Sub Convert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Convert.Click
On Error Resume Next

If (SourceFahrenheit.Checked = True) Then
' Convert from Fahrenheit to other types.
If (IsNumeric(ValueFahrenheit.Text) = True) Then
ValueCelsius.Text = _
(Val(ValueFahrenheit.text) - 32) / 1.8
ValueKelvin.Text = _
((Val(ValueFahrenheit.Text) - 32) / 1.8) + 273.15
Else
ValueCelsius.Text = "Error"
ValueKelvin.Text = "Error"
End If
ElseIf (SourceCelsius.Checked = True) Then
If (IsNumeric(ValueCelsius.Text) = True) Then
ValueFahrenheit.Text = _
(Val(ValueCelsius.Text) * 1.8) + 32
ValueKelvin.Text = Val(ValueCelsius.Text) + 273.15
Else
'invalid data
ValueFahrenheit.Text = "Error"
ValueKelvin.Text = "Error"
End If
Else
If (IsNumeric(ValueKelvin.Text) = True) Then
ValueFahrenheit.Text = _
((Val(ValueKelvin.Text) - 273.14) * 1.8) + 32
ValueCelsius.Text = Val(ValueKelvin.Text) - 273.15
Else
ValueFahrenheit.Text = "Error"
ValueCelsius.Text = "Error"
End If
End If
End Sub


Here is this same tutorial written as a console application. It comes from Visual Basic 2005 Cookbook by Tim Patrick and John Clark Craig.


Module Module1


Sub Main()
' -- The program starts here.
Dim userInput As String
Dim sourceType As String

On Error Resume Next

' Display general Instructions

Console.WriteLine("Instructions: " & vbCrLf & _
"To convert temperature, enter a starting " & _
"temperature, followed by one of the following letters: " & vbCrLf & _
" F = Fahrenheit" & vbCrLf & _
" C = Celsius " & vbCrLf & _
" K = Kelvin " & vbCrLf & _
"Enter a blank line to exit." & vbCrLf)

'--- The program continues until the user enters a blank line

Do While True
'---Prompt the user
Console.WriteLine("Enter a source temperature.")
Console.Write(">")
userInput = Console.ReadLine()

'---- A blank line exits the application
If (Trim(userInput) = "") Then Exit Do

' ---- Determine the source type.
userInput = UCase(userInput)
If (InStr(userInput, "F") > 0) Then
' ---- Start with Fahrenheit
sourceType = "F"
userInput = Replace(userInput, "F", "")
ElseIf (InStr(userInput, "C") > 0) Then
' --- Start with Celsius
sourceType = "C"
userInput = Replace(userInput, "C", "")
ElseIf (InStr(userInput, "K") > 0) Then
'---- Start with Kelvin
sourceType = "K"
userInput = Replace(userInput, "K", "")
Else
' --- invalid entry
Console.WriteLine("Invalid input: " & _
userInput & vbCrLf)
Continue Do
End If

'Check for a valid temperature.
userInput = Trim(userInput)
If (IsNumeric(userInput) = False) Then
Console.WriteLine("Invalid number: " & _
userInput & vbCrLf)
Continue Do
End If

'----Time to convert.
If (sourceType = "F") Then
' ---- convert from Fahrenheit to other types
Console.WriteLine(" Fahrenheit: " & userInput)
Console.WriteLine(" Celsius: " & _
(Val(userInput) - 32) / 1.8)
Console.WriteLine(" Kelvin: " & _
((Val(userInput) - 32) / 1.8) + 273.15)
ElseIf (sourceType = "C") Then
' ---- convert from Celsius to other types.
Console.WriteLine(" Fahrenheit: " & _
(Val(userInput) * 1.8) + 32)
Console.WriteLine(" Celsius: " & userInput)
Console.WriteLine(" Kelvin: " & _
Val(userInput) + 273.15)
Else
' --- convert from kelvin to other types.
Console.WriteLine(" Fahrenheit: " & _
((Val(userInput) - 273.15) * 1.8) + 32)
Console.WriteLine(" Celsius: " & _
Val(userInput) - 273.15)
Console.WriteLine(" Kelvin: " & userInput)

End If
Loop
End

End Sub

End Module

Sunday, January 2, 2011

Sunday 1/02/2011

First post of the new year!

----- Talking about JavaScript:

I'm using a free design environment provided by Aptana Aptana

Every window object has a property called opener


<P>
<html>
<head>
<title>Main Document</title>
<script type="text/javascript">
function newWindow() {
window.open("subwind.htm" , "sub", "height=200, width=200");
}
</script>
</head>

<body>
<form>
<input type="button" value="New Window" onclick="newWindow()">
<br>
Text incoming from subwindow:
<input type="text" name="entry">

</form>
</body>
</html>

______________________________________________________

<html>
<head>
<title>A SubDocument</title>
</head>
<body>
<form onsubmit="return false">
Enter text to be copied to the main window:
<input type="text"
onchange="opener.document.forms[0].entry.value = this.value">
</form>
</body>
</html>



Most of the objects that a browser creates for you are established when an HTML document loads into the browser.

Remember that objects are create in their load order.

When used in script statements, property names are case-sensitive.

An objects method is a command that a script can give to that object.

Some methods return values, but that is not a prerequisite for a method.

An event handler specifies how an object reacts to an event that is triggered by a user action.


<html>
<head>
<title>A Simple Page</title>
<script type="text/javascript">


function modify() {

var newElem = document.createElement("p");
newElem.id = "newP";
var newText = document.createTextNode("This is the second paragraph.");
newElem.appendChild(newText);
document.body.appendChild(newElem);
document.getElementBYId("emphasis1").childNodes[0].nodeValue = "first";
}

</script>
</head>
<body>
<button onclick="modify()">Add/Replace Text</button>

<p id="paragraph1">This is the <em id="emphasis1">one and only</em> paragraph on the page.</p>

</body>
</html>


Here is a simple JavaScript code I wrote myself



<html>
<head>
<title>Checking for an existing, nonempty string</title>
<script type="text/javascript">
var textValue

function inputScript(){
alert("I am an alert box!");
textValue = document.frmOne.inputBox1.value;
alert(textValue);
}

</script>

</head>
<body>
<form name="frmOne">
<input type="text" name="inputBox1"></input>
<input type="submit" name="inputButton1" value="Enter" onclick="inputScript()">

</form>
</body>
</html>