function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.emailAddr.value)) {
return (true);
}
alert("Invalid E-mail Address! Please re-enter.");
return (false);
} Filter
2004-05-07
Validera epostadress
Javascript
2004-05-07
Dynamiskt style sheet med javascript
Css
<html>
<head>
<title>CSS på HTML-elenment</title>
<style>
.normal { color: #ff9933; font-size: 10pt; font-style: normal; background-color: #000000; }
.hidden { color: #FFFFFF; font-size: 16pt; font-style:normal; }
.selected { color: #0000FF; font-style:normal; font-size:16pt; background-color: #ff9933; }
</style>
</head>
<body>
<table border="0">
<tr>
<td width="200" id="item1" class="normal" onmouseover="changestyle();" onmouseout="resetstyle();">Item 1</td>
<td width="200" id="iteminfo1" class="hidden">desc 1</td>
</tr>
<tr>
<td id="item2" class="normal" onmouseover="changestyle();" onmouseout="resetstyle();">Item 2</td>
<td id="iteminfo2" class="hidden">desc 2</td>
</tr>
<tr>
<td id="item3" class="normal" onmouseover="changestyle();" onmouseout="resetstyle();">Item 3</td>
<td id="iteminfo3" class="hidden">desc 3</td>
</tr>
</table>
<script language="JavaScript">
var source;
function changestyle() {
source = window.event.srcElement;
source.className = "selected";
if (item1.className == "selected") {
iteminfo1.className = "selected";
}
if (item2.className == "selected") {
iteminfo2.className = "selected";
}
if (item3.className == "selected") {
iteminfo3.className = "selected";
}
}
function resetstyle() {
source = window.event.srcElement;
source.className = "normal";
iteminfo1.className = "hidden";
iteminfo2.className = "hidden";
iteminfo3.className = "hidden";
}
</script>
</body>
</html> 2004-05-07
Decimala färger
Css
p { color: rgb(0,0,255) } 2004-05-06
Utöka existerande javascriptobjekt
Javascript
// Create the function that is going
// to extend the String-object...
function fmtHeading(level) {
htag = "h" + level;
stringtext = this.toString();
starttag = "<" + htag + ">";
stoptag = "</" + htag + ">";
return starttag + stringtext + stoptag;
}
// Connect it to the String object...
String.prototype.heading = fmtHeading;
// Let the user set a level and use it for display...
var hlevel = prompt("Level for heading? (1 - 6)", "1");
var msg = "This is a heading of level " + hlevel ;
document.write(msg.heading(hlevel)); 2004-05-06
Strängobjekt
Javascript
<script language="javascript">
document.write("<h1>String Methods</h1>");
var sample_string = "AaBbCcDdEeFfGg";
document.write("<br>Orignal String: " + sample_string);
document.write("<h2>Formatting</h2>");
document.write("<br>toLowerCase: " + sample_string.toLowerCase());
document.write("<br>toUpperCase: " + sample_string.toUpperCase());
document.write("<br>bold: " + sample_string.bold());
document.write("<br>italics: " + sample_string.italics());
document.write("<br>strike: " + sample_string.strike());
document.write("<br>big: " + sample_string.big());
document.write("<br>small: " + sample_string.small());
document.write("<br>sup: " + sample_string.sup());
document.write("<br>sub: " + sample_string.sub());
document.write("<br>fixed: " + sample_string.fixed());
document.write("<br>fontcolor(red): " + sample_string.fontcolor("#FF0000"));
document.write("<br>fontsize(-3):" + sample_string.fontsize("-3"));
document.write("<br>fixed: " + sample_string.fontsize("-3"));
document.write("<h2>Processing</h2>");
document.write("<br>substr(2, 2): " + sample_string.substr(2, 2));
document.write("<br>substring(2, 4): " + sample_string.substring(2, 4));
document.write("<br>concat(\"XxYxZz\"): " + sample_string.concat("XxYxZz"));
document.write("<br>charAt(0): " + sample_string.charAt(0));
document.write("<br>charCodeAt(0): " + sample_string.charCodeAt(0));
document.write("<br>indexOf: " + sample_string.indexOf("A"));
document.write("<br>search(\"Cc\"): " + sample_string.search("Cc"));
document.write("<br>replace(\"Cc\", \"Zz\"): " + sample_string.replace("Cc", "Zz"));
</script> 