Monday, December 27, 2010

Monday December 27 2010


<html>
<head>
<title>JS Cook 1.4</title>
<script type="text/javascript">
function inquiry() {
var testValue = "This is the cookbook's test string";
var subsValue = prompt("Enter the value you wish to search for", "");
var iValue = testValue.indexOf(subsValue);

if (iValue != -1) {
alert("We found it!");
} else {
alert("We didn't find it!");
}
}
</script>
<body onload="inquiry()">
</body>


Here is another tutorial from The JavaScript Cookbook by Shelley Powers


<html>
<head>
<title>JS Cookbook 1.5</title>
<script type="text/javascript">
function substringTest() {
var sentence = "This is one sentence. This is a sentence wih a list of items:
cherries, oranges, bananas, apples.";
alert(sentence);
var start = sentence.indexOf(":");
var end = sentence.indexOf(".", start+1);

var list = sentence.substring(start+1, end);
alert(list);
}
</script>
<body onload="substringTest()">
</body>


Here is a JavaScript tutorial from The JavaScript Bible by Danny Goodman

To bring a select object to life, use the onchange event handler.


<html>
<head>
<title>Select Navigation</title>
<script type="text/JavaScript">
function goThere() {
var list = document.forms[0].urlList;
location.href = list.options[list.selectedIndex].value;
}
</script>
</head>

<body>

<form>
Choose a place to go:
<select name="urlList" onchange="goThere()">
<option selected value = "http://www.laservault.com/">Home Page</option>
<option value = "http://www.laservault.com/Home/ContactUs/tabid/92/Default.aspx">Contact Us</option>
<option value = "http://www.laservault.com/Support/FlashTutorials/tabid/110/Default.aspx">Flash Tutorials
<option value = "httP://www.google.com/">Search the Web</option>
</select>
</form>
</body>
</html>


Last tutorial for today, tutorial 9-5 from the JavaScript Bible


<html>
<head>
<title>Beatle Picker</title>
<script type ="text/javascript">
function processData(form) {
for (var i = 0; i < form.Beatles.length; i++) {
if (form.Beatles[i].checked) {
break;
}
}
//assign values to variables for convenience
var beatle = form.Beatles[i].value;
var song = form.song.value;
alert("Checking whether " + song + " features " + beatle + "...");
}

function verifySong(entry) {
var song = entry.value;
alert("Checking whether " + song + " is a Beatles tune...");
}
</script>
</head>
<body>
<form onsubmit = "return false">
<p>Choose your favorite Beatle:
<input type="radio" name="Beatles" value="John Lennon" checked>John
<input type="radio" name="Beatles" value="Paul McCartney">Paul
<input type="radio" name="Beatles" value="George Harrison">George
<input type="radio" name="Beatles" value="Ringo Starr">Ringo



<P>Enter the name of your favorite Beatles song:<br>
<input type="text" name="song" value="Eleanor Rigby" onchange="verifySong(this)">
<Input type="button" name="process" value="Process Request..." onclick="processData(this.form)"


</form>
</body>
<html>

No comments: