Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

HTML
<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
Updated 25-Apr-13 5:03am
v2
Comments
Prasad Khandekar 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 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 C 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 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 C 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. :)

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900