Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
I'm looking for a way to connect these 2 codes
Old 03-10-2008, 12:59 AM I'm looking for a way to connect these 2 codes
Skilled Talker

Posts: 52
Name: Delon
Trades: 0
Hi Guys,

I have 2 javascript codes that I want to work together because they both use onsubmit ... the first is a "input all fields" code and the 2nd is a "popup in new window" code. They both work but what the new pop up window opens even after the message is given that the user needs to fill in all required fields. I am trying to connect both codes so here is what it looks like: i know i need to change something on the window.open code but im not sure what, anyway here is the code that i have in the <head> section:

<script type="text/javascript">
<!-- Start
function verify() {
var message = "In order for this form to be submitted all fields are required to be filled. Please complete the following field(s):"+'\n'+""+'\n'+""
if (document.form.FirstName.value=="") {
message = message + "Your First Name,"+'\n'+"";
}
if (document.form.EmailAddress.value=="") {
message = message + "Email Address,"+'\n'+"";
}
if (document.form.DomainName.value=="") {
message = message + "Registered Domain Name of your Mini-Site,"+'\n'+"";
}
//alert if fields are empty and cancel form submit
if (message == "In order for this form to be submitted all fields are required to be filled. Please complete the following field(s):"+'\n'+""+'\n'+"") {
document.form.submit();
}
else {
alert(message);
return false;
}
}
function createTarget(t)
{
window.open("", t, "width=200,height=100,left=505,top=2,");
return true;
}
// End -->
</script>



I don't think anything needs to be changed in the <body> section, i just basically need to tell this popup window to only open if all required fields have been filled because whats happening is that the message comes up prompting the user to fill all fields but the popup window opens after with the "thank you for submitting this form" message in it... which makes no sense. Please let me know what needs to be added to this code so that it will work. Thanks
oceankid is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-10-2008, 01:21 AM Re: I'm looking for a way to connect these 2 codes
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by oceankid View Post
Code:
if (message == "In order for this form to be submitted all fields are required to be filled. Please complete the following field(s):"+'\n'+""+'\n'+"") {
document.form.submit();
}
This test is ridiculously clunky. message should be initialised to "" then tested at the end to see if it has changed.

Code:
 if (message == "")
  createTarget('whatever');
 else
  alert(message="In order for this form to be submitted." + message);

 return !!!message;
Don't call the submit method, instead install the onsubmit handler thus:
Code:
<form onsubmit="return verify()" ....>
logic ali is offline
Reply With Quote
View Public Profile
 
Old 03-10-2008, 02:54 AM Re: I'm looking for a way to connect these 2 codes
Skilled Talker

Posts: 52
Name: Delon
Trades: 0
everything sounds pretty straight forward, but you kind of lost me at the part where you wrote this line:

alert(message="In order for this form to be submitted." + message);

return !!!message;
i already established earlier on that message=In order for this form to be submitted all fields are required to be filled. Please complete the following field(s):"+'\n'+""+'\n'+""

so why did you use that line ? that's the only part i don't understand
oceankid is offline
Reply With Quote
View Public Profile
 
Old 03-10-2008, 03:04 AM Re: I'm looking for a way to connect these 2 codes
Skilled Talker

Posts: 52
Name: Delon
Trades: 0
not only so but why did you use the

!!! in [return !!!message]

and what will happen to

window.open("", t, "width=200,height=100,left=505,top=2,");

this will have to be placed after createTarget('whatever') right? because i still want those window specifications for the new window it opens
oceankid is offline
Reply With Quote
View Public Profile
 
Old 03-10-2008, 10:44 AM Re: I'm looking for a way to connect these 2 codes
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by oceankid View Post
everything sounds pretty straight forward, but you kind of lost me at the part where you wrote this line:

alert(message="In order for this form to be submitted." + message);

return !!!message;
i already established earlier on that message=In order for this form to be submitted all fields are required to be filled. Please complete the following field(s):"+'\n'+""+'\n'+""

so why did you use that line ? that's the only part i don't understand
I said that message should be initialised to "". Then if any error messages get appended to it, you prepend 'please complete etc' to it, which is what
the expression in the alert does.

The function needs to return a boolean, so a double inversion !! converts an empty string to false, otherwise true. You need to return true for an empty string, hence the third inversion.
Quote:
and what will happen to

window.open("", t, "width=200,height=100,left=505,top=2,");

this will have to be placed after createTarget('whatever') right? because i still want those window specifications for the new window it opens
I thought you wanted to call createTarget upon successful validation, which is what I did. It wasn't clear what parameter you wanted to pass it.
logic ali is offline
Reply With Quote
View Public Profile
 
Old 03-11-2008, 12:45 AM Re: I'm looking for a way to connect these 2 codes
Skilled Talker

Posts: 52
Name: Delon
Trades: 0
ok i tried what you told me but it doesn't seem to work...im pretty new to javascripting so ...anyway here's how i wrote the code, now nothing happens it doesn't even alert and it open a new window but not with the parameters i gave it:

<script type="text/javascript">
<!-- Start
function verify()
{
var message = "In order for this form to be submitted all fields are required to be filled. Please complete the following field(s):"+'\n'+""+'\n'+""
if (document.form.FirstName.value=="")
{
message = message + "Your First Name,"+'\n'+"";
}
if (document.form.EmailAddress.value=="")
{
message = message + "Email Address,"+'\n'+"";
}
if (document.form.DomainName.value=="")
{
message = message + "Registered Domain Name of your Mini-Site,"+'\n'+"";
}
//alert if fields are empty and cancel form submit
if (message == "") {
createTarget(t);
window.open("", t, "width=200,height=100,left=505,top=2,");
else
alert(message="In order for this form to be submitted." + message);

return !!!message;
// End -->
</script>


let me know what I'm doing wrong
oceankid is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to I'm looking for a way to connect these 2 codes
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.91327 seconds with 12 queries