...

View Full Version : How to submit form with text link



seanenoonan
07-15-2004, 06:25 PM
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!

jamescover
07-15-2004, 06:51 PM
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

seanenoonan
07-15-2004, 06:59 PM
Thanks James. Here's my page location:

http://www.pfm.org/WilberforceTemplate.cfm?Section=National_Preaching_Initiative

The window opens, but it doesn't seem to load correctly. Any further ideas?

sad69
07-15-2004, 07:08 PM
No, I think you were on the right track to begin with.

Try this:


<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.

seanenoonan
07-15-2004, 07:19 PM
This line is giving me an error ('null' is null or not an object):

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

jamescover
07-15-2004, 07:20 PM
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

seanenoonan
07-15-2004, 07:45 PM
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/default.asp?url=/workshop/author/dhtml/reference/properties/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
07-15-2004, 07:48 PM
Check it out:

http://www.pfm.org/WilberforceTemplate.cfm?Section=National_Preaching_Initiative

jamescover
07-15-2004, 08:15 PM
<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

seanenoonan
07-15-2004, 08:25 PM
Here's my page:

http://www.pfm.org/WilberforceTemplate.cfm?Section=National_Preaching_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?

jamescover
07-15-2004, 08:39 PM
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

seanenoonan
07-15-2004, 08:52 PM
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>

sad69
07-15-2004, 09:58 PM
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.

glenngv
07-16-2004, 03:55 AM
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:


<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>

seanenoonan
07-16-2004, 03:14 PM
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()">

glenngv
07-19-2004, 04:05 AM
That's a server-side error (cold-fusion) not javascript. The error occured in the SendToFriend.cfm page. I don't know cold-fusion so I can't help you in that area.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum