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.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Sep 2002
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Passing Values Code Problem

    I currently have the following code on page 1:
    <html>
    <head>
    <title>Email Newsletter Subscription Page 1</title>
    <SCRIPT LANGUAGE="JavaScript">
    function NewPage(frmobj)
    {
    if(frmobj.email_addr.value.length==0)
    {
    alert("Please enter your email address.")
    frmobj.email_addr.focus()
    }
    else
    {
    var passemail=frmobj.email_addr.value
    linkid="page2.htm?"+passemail
    location.href=linkid
    }
    }
    </SCRIPT>
    </head>

    <body>


    <form name="newsletter" onSubmit="return NewPage()">
    EMAIL:<input name="email_addr" type="text" size="30">
    <input name="submit" type="button" id="submit" onClick="NewPage(this.form)" value="SUBMIT">
    </form>
    </body>
    </html>



    Which when submitting the form goes to page 2:

    <html>
    <head>
    <title>Email Newsletter Subscription Page 2</title>
    </head>

    <body>
    <form name="newsletter" method="post" action="/cgi-bin/newsletter.cgi">

    <p> FIRST NAME:
    <INPUT NAME="firstname" TYPE="text" id="firstname" SIZE="30">
    <p> LAST NAME:
    <INPUT NAME="lastname" TYPE="text" id="lastname" SIZE="30">
    <p> EMAIL:
    <INPUT NAME="email" TYPE="text" id="email" SIZE="30">
    <p>
    <input name="Submit" type="button" id="Submit" value="Submit">
    <SCRIPT LANGUAGE="JavaScript">
    var passdata=unescape(location.search.substring(1,location.search.length))
    document.newsletter.email.value=passdata
    </SCRIPT>
    </form>
    </body>
    </html>


    The problem is, you can't press enter to submit. It'll just create the URL query string but leave the user on the same page. I want to make sure that if the user presses enter they will be taken to page 2 and the email will still auto-populate.

    I tried doing this by simply have the form tag include an action=page2.htm but the email was auto populated with the entire querry string, not just the email value.

    Let me know if I can be more clear.

    Thanks for any help you can give!

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The basic problem is the way you're submitting the form.

    You should use <form method="get">

    If you're using javascript, or <form method="post"> if submitting to a cgi or other server-side script.

    In this case, why don't you use CGI to populate your form?
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #3
    New to the CF scene
    Join Date
    Sep 2002
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, let me clarify.

    What happens is I have a small mini-form on my home page that lets the user enter their email address. When the press submit it will take them to another page that asks for a bit more information (first name, last name, etc.). I'd like for the information that enter on the homepage (their email) to be autopopulated in the email field on page2.

    Maybe that'll make a little more sense.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could try disabling the enter key with this code:
    function KeyDownc(e)
    {
    if (!document.all)
    {var keycodec = e.which}
    else
    {var keycodec = event.keyCode}

    if(keycodec=='13')
    {return false;}
    }
    if (!document.all)
    {
    document.captureEvents(Event.KEYDOWN);
    }
    document.onkeydown=KeyDownc;

    Add this after your other function in the scripts section. Also you should remove the onSubmit in the form tag. It will not do anything since you have the onClick on your input button.
    Last edited by requestcode; 01-18-2003 at 03:32 AM.

  • #5
    New to the CF scene
    Join Date
    Sep 2002
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's definitely a work around. I guess I was really hoping they could press enter and it would work. I think to do that I am going to have change all of my code. Sigh.


  •  

    Posting Permissions

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