Sei sulla pagina 1di 9

<!-- TWO STEPS TO INSTALL EMAIL VALIDATION - BASIC: 1.

Copy the coding into the HEAD of your HTML document 2. Add the last code into the BODY of your HTML document --> <!-- STEP ONE: Paste this code into the HEAD of your HTML document --> <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- This script and many more are available free online at --> <!-- The JavaScript Source!! http://javascript.internet.com --> <!-- Begin 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) } // End --> </script> </HEAD> <!-- STEP TWO: Copy this code into the BODY of your HTML document --> <BODY> <form onSubmit="return checkEmail(this)"> E-mail Address:<br> <input type="text" name="emailAddr"> <p> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </form> <p><center> <font face="arial, helvetica" size"-2">Free JavaScripts provided<br> by <a href="http://javascriptsource.com">The JavaScript Source</a></font> </center><p> <!-- Script Size: 1.07 KB -->

<script language="JavaScript1.2"> /* Advanced Email Check By Website Abstraction (http://www.wsabstract.com) and Java-Scripts.net (http://www.java-scripts.net) Over 200+ free scripts here! */ var testresults function checkemail(){ var str=document.validation.emailcheck.value var filter=/^.+@.+\..{2,3}$/ if (filter.test(str)) testresults=true else { alert("Please input a valid email address!") testresults=false } return (testresults) } </script>

<script> function checkbae(){ if (document.layers||document.all) return checkemail() else return true } </script> <form name="validation" onSubmit="return checkbae()"> Please input a valid email address:<br> <input type="text" size=18 name="emailcheck"> <input type="submit" value="Submit"> </form>

function validate(form_id,email) {

var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; var address = document.forms[form_id].elements[email].value; if(reg.test(address) == false) { alert('Invalid Email Address'); return false; } } <form id="form_id" method="post" action="action.php" onsubmit="javascript:return validate('form_id','email');"> <input type="text" id="email" name="email" /> <input type="submit" value="Submit" /> </form>

<script language = "Javascript"> function emailcheck(str) { var at="@" var dot="." var lat=str.indexOf(at) var lstr=str.length var ldot=str.indexOf(dot) if (str.indexOf(at)==-1){ alert("The eMail address '@' convention appears to be invalid.") return false } if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ alert("The eMail address '@' convention appears to be invalid.") return false } if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ alert("The eMail address 'dot' convention appears to be invalid.") return false } if (str.indexOf(at,(lat+1))!=-1){ alert("The eMail address '@' convention appears to be invalid.") return false } if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ alert("The eMail address 'dot' convention appears to be invalid.") return false } if (str.indexOf(dot,(lat+2))==-1){ alert("The eMail address 'dot' convention appears to be invalid.") return false } if (str.indexOf(" ")!=-1){ alert("The eMail address spacing convention appears to be invalid.")

return false } return true } function ValidateForm(){ var emailID=document.myForm.txtEmail if ((emailID.value==null)||(emailID.value=="")){ alert("Please Enter your Email Address") emailID.focus() return false } if (emailcheck(emailID.value)==false){ emailID.value="" emailID.focus() return false } return true } </script> <form name="myForm" method="post" action="" onSubmit="return ValidateForm()"> Enter an eMail Address : <input type="text" name="txtEmail"> <input type="submit" name="Submit" value="Submit"> </form>
<BODY onLoad="scrollit(100)"> <SCRIPT> <!-function scrollit(seed) { var m1 = "Hope you've enjoyed your stay here!"; var m2 = " JavaScript Kit. Your ultimate"; var m3 = " source for JavaScripts!"; var m4 = ""; var msg=m1+m2+m3+m4; var out = " "; var c = 1; if (seed > 100) { seed--; cmd="scrollit("+seed+")"; timerTwo=window.setTimeout(cmd,100); } else if (seed <= 100 && seed > 0) { for (c=0 ; c < seed ; c++) { out+=" "; } out+=msg; seed--; window.status=out; cmd="scrollit("+seed+")";

timerTwo=window.setTimeout(cmd,100); } else if (seed <= 0) { if (-seed < msg.length) { out+=msg.substring(-seed,msg.length); seed--; window.status=out; cmd="scrollit("+seed+")"; timerTwo=window.setTimeout(cmd,100); } else { window.status=" "; timerTwo=window.setTimeout("scrollit(100)",75); } } } //--> </SCRIPT>

Part 1 Example:
<HEAD> Place part 1 code here </HEAD>

Part 1 Code:
<SCRIPT LANGUAGE="JavaScript"> <!-- hide from old browsers var count = 0; // Change the number after delay to change scroll speed. // Higher number equals slower scroll. var delay = 250; // text between quotes will display in the status window. // Leave blank spaces after text. var text = "Dave's Home Page... "; function scroll () { window.status = text.substring (count, text.length) + text.substring (0, count) if (count < text.length) count ++; else count = 0; setTimeout ("scroll()", delay); } // end hiding --> </SCRIPT>

Place part 2 code between the first < BODY> tag of your document. Part 2 Example:

<BODY onLoad="scroll();">

Part 2 Code:
onLoad="scroll();"

THE CODE
your document.

- Printable Versio - Send Page To F

To make this script work on your page you need to add it to the <head> section of Next you need to add onChange="DropDownMenu(this)" to each drop-down
menu that should call the script.

The onChange is added to the <select> tag of the desired


drop-down menu.

Finally you need to add the desired URL and the optional target to each of the
options in the menus.

To do this use the following syntax:


<option value="http://www.yahoo.com">Yahoo</option>

If you want to add a target to the link use this syntax:


<option value="http://www.yahoo.com&target">Yahoo</option>

where "target" is replaced by the target you want to use.

If you wanted the link to open in a frame called "main" you would add:
<option value="http://www.yahoo.com&main">Yahoo</option>

Note:
You can also use the reserved targets: "_blank"

"_top"

"_parent"

"_self"

Click here to get an explanation of these targets.

Finally, you can enter FALSE in the URL field to let the script know that the option
shouldn't load a page. This is what you do if you want one of the options to be a header for the drop-down menu - for example "SEARCH ENGINES" and "THIS SITE" in the two examples shown at the top of this page.

The script looks like this:


<script> function DropDownMenu(entered) { // ********************************* // DROP DOWN MENU (c) Henrik Petersen / NetKontoret 1998 - All rights reserved // Explained along with other useful scripts at: http://www.echoecho.com/javascript.htm // You may freely use this script as long as you do not remove this line and the 2 lines above. // ****************************************** with (entered) { // Store the selected option in a variable called ref ref=options[selectedIndex].value; // Count the position of the optional & splitcharacter=ref.lastIndexOf("&"); // The three lines below checks if a target goes along with the URL // That is: (if a "&" is in the option-value). // If so, the URL is stored in a variable called loc and the target // is stored in a variable called target. // If not the URL is stored in a variable called loc and "_self" is // stored in the variable called target. if (splitcharacter!=-1) {loc=ref.substring(0,splitcharacter); target=ref.substring(splitcharacter+1,1000).toLowerCase();} else {loc=ref; target="_self";}; // create a varible called lowloc to store loc in lowercase characters. lowloc=loc.toLowerCase(); // Skip the rest of this function if the selected optionvalue is "false". if (lowloc=="false") {return;}

// Open link in current document if (target=="_self") {document.location=loc;} // Cancel eventual framesets and open link in current window else {if (target=="_top") {top.location=loc;} // Open link in new window else {if (target=="_blank") {window.open(loc);} // Open link in parent frame else{if (target=="_parent") {parent.location=loc;} // Open link in the specified frame else {parent.frames[target].location=loc;}; }}}} } </script>

JAVASCRIPT DIGITAL CLOCK In this article we are going to design a JavaScript based Digital Clock. Here we are see use a HTML Form to show our Digital Clock. Take a look below on piece of code <form name = "clockForm"> <input type="text" name="clock" size="10" class="frm" /> </form> Here we have defined HTML form. And use input and assign a class frm to it. Class frm will take care of representation of clock. .frm { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #164BA0; background-color: #D1D1D1; border: 1px solid #83AAD3; } Now we have to add JavaScript which will generate Digital clock for us. Now we define a function Display() and going to call it through Window object supports methodssetTimeout() to call same function after every 1000 milliseconds. The Window object supports methods for setting timers that we might use to perform a variety of functions. These methods include setTimeout() and clearTimeout(). The basic idea is to set a timeout to trigger a piece of script to occur at a particular time in the future. The general syntax is timerId = setTimeout(script-to-execute, time-in-milliseconds); As the Display() get called after every 1000 milliseconds recursively. A new value by Date() class gets stored in variable Today. Date class is mostly used for define and manipulate dates. You can get current time as well as date. You can also perform calculation based on date or times using date class. This is not a reserved word so you can declare your own variable or function called Date but if you do then you will not be able to use the Date class. See following piece of code for Display() function display() { var Today = new Date(); var hours = Today.getHours();

var min = Today.getMinutes(); var sec = Today.getSeconds(); var Time = ((hours > 12) ? hours - 12 :(hours == 0) ? 12 :hours); Time += ((min < 10) ? ":0" : ":") + min; Time += ((sec < 10) ? ":0" : ":") + sec; Time += (hours >= 12) ? " PM" : " AM"; this.clockForm.clock.value = Time; setTimeout("display()",1000); } display(); Our Clock will look like below image...

Here we are also converting 24 hour Clock into 12 hour with help of conditional operator. The conditional operator is another form of an if condition. It takes three parameters. The syntax looks like this: (Condition) ? val1: val2. If condition is true then it will return val1 otherwise val2. EXAMPLE:

Potrebbero piacerti anche