Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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!

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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. "

  • #3
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 + "'>";

  • #6
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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. "

  • #7
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #8
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    James, I reposted your code...


  • #9
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <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
    Last edited by jamescover; 07-15-2004 at 07:23 PM.
    "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. "

  • #10
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

  • #11
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Last edited by jamescover; 07-15-2004 at 08:32 PM.
    "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. "

  • #12
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #13
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #14
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #15
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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()">


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •