Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript HTML
In my html page i inserted a submit button and when the button is clicked 3 javascript functions named xyZ(),abC(),deF() need to be executed.
 
When all the 3 functions are executed successfully then only i want to show the hello.html page.
 
But now i am getting the hello.html page even if the functions don't get executed successfully.
 
<script>
function open_win()  {
    if(xyZ() && abC() && deF())            
        window.open("hello.html","_blank","width=400");
    else
        alert("Register Again");
}
</script>
<html> 
<input type="submit" onclick="xyZ(),abC(),deF(),open_win()">
</html>
what should i write to correct the problem?
Posted 25-Apr-13 4:42am
sash_kp367
Edited 25-Apr-13 6:03am
(no name)47.4K
v2
Comments
Prasad Khandekar at 25-Apr-13 11:04am
   
Change the type to button instead of submit. Your HTML is very wrong though. form elements should be placed inside the form element, which inturn will be placed insde body element. Similarly I will suggest to move script inside the head element.
 
And also change button code as
 
<input type="button" önclick="open_win()"/>
 
if you want to call all the function before open_win call even though your are calling them from open_win then change the button code as
 
<input type="button" önclick="xyz();abc();def();open_win();"/>
sash_kp at 25-Apr-13 13:57pm
   
Actually i have designed a registration form in which first name,last name,user name,password etc are there.I have written validation codes for each of these individually in separate functions.One function for one validation.Like,fname() for first name and so on.
 
I have also designed an html page which i want to show on successful validations of all the fields.But for that all the functions are needed to be executed first,if all the validations are satisfied,then only the html page saying "registration successful" will be displayed.
Chinmaya_Champatiray at 25-Apr-13 12:09pm
   
Don't know why you are invoking xyZ(), abC(), deF() twice. one by onClick event and the other time you are invoking in open_win().
 
And one more thing are you sure you are returning true/false based on the success or unsuccessful execution of these functions?
sash_kp at 25-Apr-13 13:56pm
   
Actually i have designed a registration form in which first name,last name,user name,password etc are there.I have written validation codes for each of these individually in separate functions.One function for one validation.Like,fname() for first name and so on.
 
I have also designed an html page which i want to show on successful validations of all the fields.But for that all the functions are needed to be executed first,if all the validations are satisfied,then only the html page saying "registration successful" will be displayed.
 
Chinmaya_Champatiray at 26-Apr-13 0:28am
   
I think you need to modify the below statement
<input type="submit" önclick="xyZ(),abC(),deF(),open_win()">
to
<input type="button" önclick="return open_win();"/>
 
and in open_win() :
function open_win() {
if(xyZ() && abC() && deF())
window.open("hello.html","_blank","width=400");
else
alert("Register Again");
}
 
and modify all other function to:
function xyZ(){
if(...) // your validation goes here
{
return true;
}
else
{
return false;
}
}
 
similarly modify all other functions as above.
 
hope this will help. :)
sash_kp at 26-Apr-13 4:09am
   
It somehow worked for me...Thanks a lot for your suggestion...":)"...putting all other functions inside open_win() and returning true or false...Especially These 2 ideas worked for me.
Chinmaya_Champatiray at 26-Apr-13 4:42am
   
Are you facing any other problem??
sash_kp at 28-Apr-13 7:47am
   
Nope boss..for the time being i am not..I 'll let you know once i have some bug..Thanks..":)"
Chinmaya_Champatiray at 29-Apr-13 3:01am
   
Welcome. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 584
1 Maciej Los 275
2 DamithSL 233
3 Sergey Alexandrovich Kryukov 209
4 BillWoodruff 200
0 OriginalGriff 6,803
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,421
3 Manas Bhardwaj 4,841
4 Maciej Los 4,330


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 25 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100