Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-15-2004, 05:25 PM   PM User | #1
seanenoonan
New to the CF scene

 
Join Date: Jul 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
seanenoonan is an unknown quantity at this point
How to submit form with text link

Can't seem to get my text link to submit my form. Here's my code:

------------

<form action="/TellAFriend/SendToFriend.cfm" method="post" name="TellaFriendform" target="myWindowName" onSubmit="window.open('/TellAFriend/SendToFriend.cfm','myWindowName','width=400,height=375');" >
<script language="JavaScript" type="text/javascript">
<!--
function doform()
{
document.write("<input type='hidden' name='PageLinkStatic' value='" + window.location + "'>")
document.write("<input type='hidden' name='Title' value='" + document.title + "'>")
document.TellaFriendform.submit();
}
//-->
</script>
Click <a href="javascript:doform()">here</a> to tell a friend.
</form>

------------

Can anyone help? Thanks!
seanenoonan is offline   Reply With Quote
Old 07-15-2004, 05:51 PM   PM User | #2
jamescover
Regular Coder

 
Join Date: Aug 2002
Location: USA
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
jamescover is an unknown quantity at this point
I'm not exactly sure what you're trying to do, but maybe something closer to:


<script>
<!--

function doform(){
myWin = window.open('/TellAFriend/SendToFriend.cfm','winName','width=400,height=375');
myWin.document.open();
myWin.document.writeln("<input type='hidden' name='PageLinkStatic' value='" + window.location + "'>")
myWin.document.writeln("<input type='hidden' name='Title' value='" + myWin.document.title + "'>")
myWin.document.close();
}

//-->
</script>



Click <a href="javascript:doform();">here</a> to tell a friend.
</form>


-james
__________________
"God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "
jamescover is offline   Reply With Quote
Old 07-15-2004, 05:59 PM   PM User | #3
seanenoonan
New to the CF scene

 
Join Date: Jul 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
seanenoonan is an unknown quantity at this point
I think we're getting somewhere...

Thanks James. Here's my page location:

http://www.pfm.org/WilberforceTempla...ing_Initiative

The window opens, but it doesn't seem to load correctly. Any further ideas?
seanenoonan is offline   Reply With Quote
Old 07-15-2004, 06:08 PM   PM User | #4
sad69
Senior Coder

 
Join Date: Feb 2004
Posts: 1,206
Thanks: 0
Thanked 0 Times in 0 Posts
sad69 is an unknown quantity at this point
No, I think you were on the right track to begin with.

Try this:
Code:
<form action="/TellAFriend/SendToFriend.cfm" method="post" name="TellaFriendform" id="TellaFriendform" target="myWindowName" onSubmit="window.open('/TellAFriend/SendToFriend.cfm','myWindowName','width=400,height=375');" >
<script language="JavaScript" type="text/javascript">
<!--
function doform()
{
var frm = document.getElementById(TellaFriendform);
frm.innerHTML += "<input type='hidden' name='PageLinkStatic' value='" + window.location + "'>";
frm.innerHTML += "<input type='hidden' name='Title' value='" + document.title + "'>";
frm.submit();
}
//-->
</script>
Click <a href="javascript:doform()">here</a> to tell a friend.
</form>
That should do the trick I should think.. let me know.
Sadiq.
sad69 is offline   Reply With Quote
Old 07-15-2004, 06:19 PM   PM User | #5
seanenoonan
New to the CF scene

 
Join Date: Jul 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
seanenoonan is an unknown quantity at this point
Almost there...

This line is giving me an error ('null' is null or not an object):

frm.innerHTML += "<input type='hidden' name='Title' value='" + document.title + "'>";
seanenoonan is offline   Reply With Quote
Old 07-15-2004, 06:20 PM   PM User | #6
jamescover
Regular Coder

 
Join Date: Aug 2002
Location: USA
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
jamescover is an unknown quantity at this point
The window opens, but it doesn't seem to load correctly. Any further ideas?

Need a better explaination than that...?


By the time I viewed the page, it had sad69's script in it....



-james
__________________
"God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "
jamescover is offline   Reply With Quote
Old 07-15-2004, 06:45 PM   PM User | #7
seanenoonan
New to the CF scene

 
Join Date: Jul 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
seanenoonan is an unknown quantity at this point
I like sad69's code, but I'm not sure about this line:

frm.innerHTML += "<input type='hidden' name='Title' value='" + document.title + "'>";


Says here (http://msdn.microsoft.com/library/de.../innerhtml.asp) that it is read-only for TITLE. Does that rule apply here? If so, do we have to abandon sad69's code?
seanenoonan is offline   Reply With Quote
Old 07-15-2004, 06:48 PM   PM User | #8
seanenoonan
New to the CF scene

 
Join Date: Jul 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
seanenoonan is an unknown quantity at this point
James, I reposted your code...

Check it out:

http://www.pfm.org/WilberforceTempla...ing_Initiative
seanenoonan is offline   Reply With Quote
Old 07-15-2004, 07:15 PM   PM User | #9
jamescover
Regular Coder

 
Join Date: Aug 2002
Location: USA
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
jamescover is an unknown quantity at this point
<input type='hidden' name='PageLinkStatic' value='http://www.pfm.org/WilberforceTemplate.cfm?Section=National_Preaching_Initiative'>
<input type='hidden' name='Title' value=''>



The above is what is written to the popup you're opening using the code I posted.

What is it you are trying to do? Do you want to create a new document using Javascript or Cold Fusion? Are you trying to pass data to a backend script, or just pass form values to the next page?



If this what you want, you can do away with the form, assuming it'll be submitted from the popup:


<script>
<!--

function doform(){
myWin = window.open('','winName','width=400,height=375');
myWin.document.open();
myWin.document.writeln("<html>");
myWin.document.writeln("<head>");
myWin.document.writeln("<title>PFM | Send This Page to a Friend<\/title>");
myWin.document.writeln("<\/head>");
myWin.document.writeln("<LINK REL=\"StyleSheet\" HREF=\"/Styles/Styles.css\" type=\"text/css\">");
myWin.document.writeln("<body bgcolor=\"#FFFFFF\">");
myWin.document.writeln("<table width=\"100%\" cellpadding=\"5\" cellspacing=\"0\" border=\"0\">");
myWin.document.writeln("<tr>");
myWin.document.writeln("<td><form>");
myWin.document.writeln("<input type='hidden' name='PageLinkStatic' value='" + window.location + "'>")
myWin.document.writeln("<input type='hidden' name='Title' value='" + myWin.document.title + "'>");
myWin.document.writeln("<\/form><\/td><\/tr><\/table>");
myWin.document.writeln("<\/body>");
myWin.document.writeln("<\/html>");
myWin.document.close();
}

//-->
</script>




Click <a href="javascript:doform();">here</a> to tell a friend.


innerHTML is not x-browser/backwards friendly...





-james
__________________
"God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

Last edited by jamescover; 07-15-2004 at 07:23 PM..
jamescover is offline   Reply With Quote
Old 07-15-2004, 07:25 PM   PM User | #10
seanenoonan
New to the CF scene

 
Join Date: Jul 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
seanenoonan is an unknown quantity at this point
What I'm trying to do...

Here's my page:

http://www.pfm.org/WilberforceTempla...ing_Initiative

You'll see I have an "EMAIL A FRIEND" image under the left nav. I want to call that same for with a text link in the right-hand column. It should pull up the same pop-up and pass the values (window.location and document.title).

I'll probably add some NOSCRIPT code later.

This help?
seanenoonan is offline   Reply With Quote
Old 07-15-2004, 07:39 PM   PM User | #11
jamescover
Regular Coder

 
Join Date: Aug 2002
Location: USA
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
jamescover is an unknown quantity at this point
I think you're doing too much work. You can grab those window properties from the child window:

Try this:


<script>
<!--

function getProps(){

myWin = window.open("","","");
myWin.document.open();
myWin.document.writeln("<a href=\"javascript:alert(window.opener.location);\">window.opener.location<\/a>");
myWin.document.writeln("<a href=\"javascript:alert(window.opener.document.title);\">window.opener.document.title<\/a>");
myWin.document.close();
}

//-->
</script>

<a href="javascript:getProps();">getProps</a>


So why not pass these to the Cold Fusion script...



-james
__________________
"God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

Last edited by jamescover; 07-15-2004 at 08:32 PM..
jamescover is offline   Reply With Quote
Old 07-15-2004, 07:52 PM   PM User | #12
seanenoonan
New to the CF scene

 
Join Date: Jul 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
seanenoonan is an unknown quantity at this point
I think I'm getting in over my head. I don't really understand "<\/a>" for starters. I guess since I've already got the form working perfectly in the left nav using an image submit that it wouldn't be that difficult to simply convert to a link submit. Maybe I'm wrong.

I still don't understand why this code doesn't work:

<form action="/TellAFriend/SendToFriend.cfm" method="post" name="TellaFriendform" target="myWindowName" onSubmit="window.open('/TellAFriend/SendToFriend.cfm','myWindowName','width=400,height=375');" >
<script language="JavaScript" type="text/javascript">
<!--
document.write("<input type='hidden' name='PageLinkStatic' value='" + window.location + "'>")
document.write("<input type='hidden' name='Title' value='" + document.title + "'>")
function doform()
{
document.TellaFriendform.submit();
}
//-->
</script>
Click <a href="javascript:doform()">here</a> to tell a friend.
</form>
seanenoonan is offline   Reply With Quote
Old 07-15-2004, 08:58 PM   PM User | #13
sad69
Senior Coder

 
Join Date: Feb 2004
Posts: 1,206
Thanks: 0
Thanked 0 Times in 0 Posts
sad69 is an unknown quantity at this point
Because you're doing the document.write(), but where are you writing it? document.write() just appends to the end of the page, so in your case, you wouldn't be writing those hidden elements within your form tags, so those hidden inputs wouldn't get submitted.

That's why I gave you my code to grab the form element, and append to the end of its innerHTML. I'm not sure why it isn't working for you... did you set the 'id' of the form tag like I showed you in my post? That way you use getElementById to get that element, and then write to the end of it.

Sadiq.
sad69 is offline   Reply With Quote
Old 07-16-2004, 02:55 AM   PM User | #14
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
Quote:
Originally Posted by sad69
That's why I gave you my code to grab the form element, and append to the end of its innerHTML. I'm not sure why it isn't working for you... did you set the 'id' of the form tag like I showed you in my post? That way you use getElementById to get that element, and then write to the end of it.
Sadiq.
The reason it didn't work is because you missed the quotes.

var frm = document.getElementById('TellaFriendform');

But here's the simplest solution:
Code:
<form action="/TellAFriend/SendToFriend.cfm" method="post" name="TellaFriendform" target="myWindowName" onSubmit="window.open('about:blank',this.target,'width=400,height=375');">
<input type="hidden" name="PageLinkStatic" />
<input type="hidden" name="Title" />
<script language="JavaScript" type="text/javascript">
<!--
function doform()
{
    var f = document.TellaFriendform;
    f.PageLinkStatic.value = location.href;
    f.Title.value = document.title;
    f.submit();
    return false;
}
//-->
</script>
Click <a href="#" onclick="return doform()">here</a> to tell a friend.
</form>
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 07-16-2004, 02:14 PM   PM User | #15
seanenoonan
New to the CF scene

 
Join Date: Jul 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
seanenoonan is an unknown quantity at this point
Thanks Glenn, but I still get an error:
Error Occurred While Processing Request
Error Diagnostic Information
Just in time compilation error

Invalid parser construct found on line 182 at position 43. ColdFusion was looking at the following text:

"
Invalid expression format. The usual cause is an error in the expression structure.
The last successfully parsed CFML construct was dynamic text (a CFML expression) occupying document position (166:43) to (166:63).

The specific sequence of files included or processed is:
D:\USERS\PFM\WWW\WILBERFORCETEMPLATE.CFM
D:\USERS\PFM\WWW\WILBERFORCENPI.CFM CFInclude

The error occurred while processing an element with a general identifier of (CFINCLUDE), occupying document position (285:3) to (285:43).


Date/Time: 07/16/04 09:13:08
Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)
Remote Address: 206.154.235.76
Query String: Section=National_Preaching_Initiative
The error appears after I add this line:
<a href="#" onclick="return doform()">
seanenoonan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 10:26 AM.


Advertisement
Log in to turn off these ads.