...

View Full Version : Passing Values Code Problem



abacus566
01-18-2003, 01:30 AM
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!

whammy
01-18-2003, 01:54 AM
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?

abacus566
01-18-2003, 03:40 AM
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.

requestcode
01-18-2003, 04:26 AM
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.

abacus566
01-18-2003, 04:53 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum