You are here: DEVPPL Forum Programming JavaScript Forum
NOTIFICATIONS
54.060
MEMBERS
15.677
TOPICS
62.241
POSTS
  562
FLASH GAMES
7.740
TUTORIALS
 

Login

E-mail:
Password:

Combine 2 'Events' to get one action at the same time

0

Loading

Combine 2 'Events' to get one action at the same time

Postby NothingLose » Mon May 02, 2005 4:59 am

Hi, :D

I like to make two JavaScript 'Events' to happen at the same time,
Here HTML code:
Code: Select all
  <form id="loginDetails" name="loginDetails" method="POST"  action="--WEBBOT-SELF--"     onSubmit="return checkEntries(this)
  onSubmit= "return emailCheck(this.Email.value)">


Is it possible to Combine two Events and let them do an action at the same time?

1. onSubmit="return checkEntries(this)"
2. onSubmit= "return emailCheck(this.Email.value)"

regards
NothingLose
 
Reputation: 0
Posts: 28
Joined: Fri Apr 08, 2005 8:26 am
Highscores: 0
Arcade winning challenges: 0

Combine 2 'Events' to get one action at the same time - Sponsored results

Sponsored results

Login to get rid of ads

 

0

Loading

Postby Dafunkymunky » Mon May 02, 2005 7:24 am

hi nothing2lose
oh yes there are two ways to do it(or maybe more)
i'll tell you two ways

one is callone function and at the end of the first function call the second function
like this

function function1()
{
-------
-------
-----
function2();
}
function function2()
{
------
-----
-----
}
<onsubmit="function1()">

or the second way is call both of them together
i.e
<onsubmit="function1();function2()">
here are example codes
1.....

<HTML>
<script language="javascript">
function function1()
{
alert("this is from function1");
//call the second function here
function2();
}
function function2()
{
alert("this is from function2")
}
</script>
<input type=Button value="click here" onclick="function1()">
</HTML>


and


<HTML>
<script language="javascript">
function function1()
{
alert("this is from function1");
}
function function2()
{
alert("this is from function2")
}
</script>
<input type=Button value="click here" onclick="function1();function2()">
</HTML>

--DAFUNKYMYNKY
--------DAFUNKYMUNKY--------
::THE::NECESSARY::[D]EVIL::
....errr i mean munky....
Dafunkymunky
 
Reputation: 0
Posts: 183
Joined: Fri Apr 08, 2005 8:32 am
Location: India
Highscores: 0
Arcade winning challenges: 0
0

Loading

Postby NothingLose » Mon May 02, 2005 11:48 am

Hi dafunkymunky,

I tried both, did not work. The problem is that I have in the two functions RETURN value.
Here is HTML page:

Code: Select all
<script type="text/javascript">
    <!--
    function checkEntries(frm)
    {
        // Ensure something has been entered for a username
        if (frm.UserName.value == "")
        {
            alert('You must provide a username to login');
            frm.UserName.focus();
            return false;
        }   
        if (frm.Country.value == "")
        {
            alert('You must provide a country to login');
            frm.Country.focus();
            return false;
        }
        // Ensure something has been entered for a password
        else if (frm.Password.value == "")
        {
            alert('You must provide a Password to login');
            frm.Password.focus();
            return false;
        }
        // Ensure the Passwordis at least six characters
        else if (frm.Password.value.length < 6)
        {
            alert('The Passwordmust be at least six characters');
            frm.Password.focus();
            frm.Password.select();
            return false;
        }
        // If the confirmation passowrd doesn't match the original password,
        // show an error message, set focus back to the field, and highlight the entry.
        else if (frm.PasswordConfirm.value != frm.Password.value)
        {
            alert('The confirmation Passworddoes not match the original password');
            frm.PasswordConfirm.focus();
            frm.PasswordConfirm.select();
            return false;
        }
        return true;
    }
</script>
<script type="text/javascript">
<!-- Begin

function emailCheck (emailStr) {

var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}

if (user.match(userPat)==null) {

alert("The username doesn't seem to be valid.");
return false;
}

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}

if (checkTLD && domArr[domArr.length-1].length!=2 &&
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

if (len<2) {
alert("This address is missing a hostname!");
return false;
}
return true;
}

function function3(){
if(!checkEntries(this))return false
if(!emailCheck(this.Email.value))return false
return true
}
//  End -->
</script>

NothingLose
 
Reputation: 0
Posts: 28
Joined: Fri Apr 08, 2005 8:26 am
Highscores: 0
Arcade winning challenges: 0
0

Loading

Postby Malcolm » Mon May 02, 2005 7:01 pm

Code: Select all
function f1(){
 {code}
 return true
}

function f2(){
 {code}
 return true
}

function call_me(){
 if(f1() && f2()){
   return true;
  }else{
   return false;
  }
}
Image
Malcolm
 
Reputation: 0
Posts: 198
Joined: Thu Oct 07, 2004 10:53 pm
Location: Ontario, Canada
Highscores: 0
Arcade winning challenges: 0
0

Loading

Postby NothingLose » Tue May 03, 2005 3:11 am

Hi,
Thanx Malcolm & dafunkymunky :D

Three of them did not work, and seems alot of headache, so I decided to safe my time and concetrate on other stuff :wink:

ciao.
NothingLose
 
Reputation: 0
Posts: 28
Joined: Fri Apr 08, 2005 8:26 am
Highscores: 0
Arcade winning challenges: 0
0

Loading

Postby Dafunkymunky » Wed May 04, 2005 9:24 am

hi nothing to lose

well i'm not very sure how the return worksw but why dont you create 2 global variables and sture t or F in them and fiunally check if both of them are true

this is how it should go about

creatye 2 global variables

function func1()
{
//here if it is false store F if true Store T

}

function func2()
{
//here if it is false store F if true Store T in the second variable

}

function func3()
{

func1()
func2()
if variables are true
do somthing

}

what we do is call func3 on submit and then in the func3 call 1 @ 2 and check if they are false

this should work

-DAFUNKYMUNKY
--------DAFUNKYMUNKY--------
::THE::NECESSARY::[D]EVIL::
....errr i mean munky....
Dafunkymunky
 
Reputation: 0
Posts: 183
Joined: Fri Apr 08, 2005 8:32 am
Location: India
Highscores: 0
Arcade winning challenges: 0
0

Loading

here is the solution

Postby Dafunkymunky » Thu May 05, 2005 11:05 am

hi nothing2lose

Code: Select all
<HTML>
<script language=javascript>
function func1()
   {
   if(document.form1.text1.value==1)
   return true;
   else
   return false;
   }
function func2()
   {
   if(document.form1.text2.value==1)
   return true;
   else
   return false;
   }
function func3()
   {
   var x
   var y
   x=func1()
   y=func2()
   if(x==true && y==true)
   alert("true")
   else
   alert("false")
   }
</script>
<form name="form1">
<input type=text name=text1>
<input type=text name=text2>
<input type="button" value="Click here" onClick="func3()">
what happens in this probram is only if both values in text box is 1
"true" meaasage will be displayed else "false" will be displayed
</form>
</HTML>



this is what exactly you want
--------DAFUNKYMUNKY--------
::THE::NECESSARY::[D]EVIL::
....errr i mean munky....
Dafunkymunky
 
Reputation: 0
Posts: 183
Joined: Fri Apr 08, 2005 8:32 am
Location: India
Highscores: 0
Arcade winning challenges: 0
^ Back to Top