Example 8
Redirection to another site from the current page can be done using the
javascript loaction property of the document object
The document object has numerous properties some of which belong to the
form object which has to inherit from the document
object whereas some of which are direct properties.
<html>
<body>
<script language="javascript">
function clickhere()
{
document.location="www.yahoo.com";
}
</script>
<input type="button" name="b1" value="Click!"
onClick="javascript:clickhere()">
</body>
</html>
Regular Expressions
The javascript built-in functions can match,replace,testand split a
string depending upon the regular expression
using the RegExp object's value.
Example
9
This script matches any non-numeric input.
^ symbol inside the [ ] means exclude the characters inside [ ], *
stands for zero or more times, + stands for 1 or more times ,
a single ? for a single character and . stands for 0 or 1 character.
<html>
<body>
<script language="javascript">
var r=new RegExp("[^0-9][a-z]*[A-Z]*");
var str="Apple";
if(r.test(str))
{
alert("Matching true dear");
}
else
{
alert("Matching false dear");
}
</script>
</body>
</html>
Go To
Index
|