...

View Full Version : Problem combining this code into one function



yombull
06-08-2004, 02:49 PM
I need to combine these three functions into one function so that it will work on the form when the submit button is clicked. I can get each function to work individually but I get errors when I try to use all of them. I have tried several different ways (guesses) to try and combine them into one function but my lack of javascript knowledge only creates frustration and more errors. Any help is appreciated.

function IGI_validate()
{

if ( (document.subscription.Name.value == '')
|| (document.subscription.Email.value == '')
|| (document.subscription.EmailConfirm.value == ''))
{
alert("Please fill out the form fields completely.")
return false
}
}

function emailcheck() {
var e=document.subscription.Email.value
if ((e.indexOf("@")==-1)||
(e.indexOf(".")==-1))
{
alert("Please input a valid email address!")
document.subscription.Email.focus()
}
}

function emailsMatch(document.subscription.Email.value,document.subscription.EmailConfirm.value)
{
if (document.subscription.Email.value != document.subscription.EmailConfirm.value)
{
alert("You're Email Addresses do not match!");
return false;
}
return true;
}

Thanks for your help!

sage45
06-08-2004, 02:58 PM
Try this:
function validate(){

var e=document.subscription.Email.value
if ((e.indexOf("@")==-1)||
(e.indexOf(".")==-1))
{
alert("Please input a valid email address!")
document.subscription.Email.focus()
}

if ((document.subscription.Name.value == '') || (document.subscription.Email.value == '') || (document.subscription.EmailConfirm.value == ''))
{
alert("Please fill out the form fields completely.")
return false
}

if (document.subscription.Email.value != document.subscription.EmailConfirm.value)
{
alert("You're Email Addresses do not match!");
return false;
}

return true;
}HTH,

-sage-

glenngv
06-10-2004, 06:48 AM
Save yourself from typing.


function validate(f){

var e=f.Email.value
if ((e.indexOf("@")==-1)|| (e.indexOf(".")==-1))
{
alert("Please input a valid email address!")
f.Email.focus()
return false;
}

if ((f.Name.value == '') || (f.Email.value == '') || (f.EmailConfirm.value == ''))
{
alert("Please fill out the form fields completely.")
return false
}

if (f.Email.value != f.EmailConfirm.value)
{
alert("You're Email Addresses do not match!");
return false;
}

return true;
}
...
<form onsubmit="return validate(this)">
...
<input type="submit" />
</form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum