/    Sign up×
Community /Pin to ProfileBookmark

Passing form values between pages

I apologize for the compexity of this, but I could sure use some help with this…

I have two variables that I would like to pass to a new URL via a form input along with a third string input by the user (their name). The city and st variables do indeed change. You will see the two variables included within the hidden input types below. The name does indeed make it to the new form but the actual values of the two variables do not. Is there a way to do this? An example follows:

var city = “Tucson”;
var st = “Arizona”;

<script language=”Javascript”>
<!–
document.write(“<FORM NAME=”myform” ACTION=”http://mypage.com/index.html” METHOD=”post”>”);
document.write(“Please type your name”);
document.write(“<INPUT TYPE=”text” NAME=”name” VALUE=””>”);
document.write(“<INPUT TYPE=”submit” NAME=”button” Value=”Enter Name” >”);
document.write(“<input type=”hidden” name=”city” [B]value=city[/B]>”);
document.write(“<input type=”hidden” name=”state” [B]value=st[/B]>”);
document.write(“</FORM>”);
// –>
</script>

Thanks!
Frank

to post a comment
HTML

5 Comments(s)

Copy linkTweet thisAlerts:
@ray326Sep 25.2007 — (De-hijacked the post.)
Copy linkTweet thisAlerts:
@FPC3authorSep 26.2007 — I found a way to make it work. Can anyone explain why this works and my previous arrangement didn't?

<script language="Javascript">

<!--

document.write("<FORM NAME="myform" ACTION="http://www.atwebpages.com/index.html" METHOD="post">");

document.write("Please type your name (cookies must be enabled): <BR><BR>");

document.write("<INPUT TYPE="text" NAME="name" VALUE="">");

document.write("<INPUT TYPE="submit" NAME="button" Value="Enter Name" onClick="testResults(this.form)">");

document.write("<BR><BR>After entering name, please wait a few seconds for new page to display.");

[B]document.write("<input type="hidden" name="city" value=");

document.write(city);

document.write(">");

document.write("<input type="hidden" name="state" value=");

document.write(st);

document.write(">");

document.write("</FORM>");[/B]
// -->

</script>
Copy linkTweet thisAlerts:
@ray326Sep 26.2007 — Because the value of city and st are not substituted within a string. This should work the same (but it's untested).

document.write('<input type="hidden" name="city" value="'+city+'">');
Copy linkTweet thisAlerts:
@FPC3authorSep 26.2007 — Thanks Ray.

I'll give that a shot!
Copy linkTweet thisAlerts:
@FPC3authorSep 26.2007 — Thanks again Ray.

It worked perfectly!

Frank
×

Success!

Help @FPC3 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...