Javascript

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsWeb Design & DevelopmentJavascript

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old July 16th, 2011, 07:36 AM
ravi951 ravi951 is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jul 2011
Posts: 3 ravi951 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 59 sec
Reputation Power: 0
Simple form integrator using javascript functions

hi all,
i want to create a simple form with 5 fields name, email-id,password,retype password and telephone number the conditions are name & password must be valid,password and retype password should match and phone no must be of 10 digits.
i have written functions for all this in javascript.tell me how to integrate to create a simple form with above fields.

kindly please integrate the functions and give me so that when i click submit button it should accept.

below is the function,when i click submit button if any errors found it should display or else it should accept.

<html>
<head>

<SCRIPT LANGUAGE="JavaScript">

function checkForm(form) /* for user name */
{
if(form.username.value == "")
{
alert("Error: Username cannot be blank!");
form.username.focus();
return false;
}
}

function checkEmail(myForm) /* for email validation*/
{
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.emailAddr.value))
{
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}

function validatePwd() /*password & retype-password verification*/
{
var invalid = " ";
var minLength = 6;
var pw1 = document.myForm.password.value;
var pw2 = document.myForm.password2.value;

if (pw1 == '' || pw2 == '')
{
alert('Please enter your password twice.');
return false;
}

if (document.myForm.password.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Try again.');
return false;
}

if (document.myForm.password.value.indexOf(invalid) > -1)
{
alert("Sorry, spaces are not allowed.");
return false;
}
else
{
if (pw1 != pw2)
{
alert ("You did not enter the same new password twice. Please re-enter your password.");
return false;
}
else
{
alert('Nice job.');
return true;
}
}
}

function ValidPhone(aphone) /* phone no validation */
{
var valid = "0123456789";
if(aphone=="")
{
alert ("This field is required. Please enter phone number");
return false;
}
if(aphone.length !=10)
{
alert("Invalid phone number length! Please try again.");
return false;
}
for (var i=0; i < aphone.length; i++)
{
temp = "" + aphone.substring(i, i+1);
if (valid.indexOf(temp) == "-1")
{
alert("Invalid characters in your phone. Please try again.");
return false;
}
}
return true;
}

</script>
</HEAD>
<BODY>
<form name=myForm onSubmit="return validatePwd()">
Name:<input type=name name=name size="25">
<br>
E-Mail:<input type=email name=email size="25">
<br>
Password: <input type=password name=password maxlength=12 size="25">
<br>
Retype password: <input type=password name=password2 maxlength=12 size="25">
<br>
PhoneNo:<input type=phoneno name=phoneno maxlength=10 size="25">
<br>
<input type=submit value="Submit">
</form>
</html>

Reply With Quote
Reply

Viewing: Tutorialized ForumsWeb Design & DevelopmentJavascript > Simple form integrator using javascript functions


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap