View Full Version : Hidden Input AND Print

Jan 14th, 2007, 02:23 AM
I want to include a passed variable as an html hidden input variable. It is passed in the URL.

I know nothing about javascript.
I am given code by www.Aweber.com to pass the name and email address to the 'Thank You Page'.

That thank you page is actually a second form.
I want to have the second form populate the name and email address fields with the passed variables.

It would be nice to have the actual text display in the text box, so the user could change it if desired.

The code I was given only allows me to Print the variable.

I tried this code, but it didn't work.

<INPUT TYPE="hidden" name="fname" value='<script>printElement('custom fname')</script>'>

Here is the code that goes where I want to display the passed variable.

<script>printElement("custom fname")</script>

And here is the code in the head to make this work.


And this is calling their Javascript;
<script language="JavaScript1.2">
// Trivial CGI variable display code Copyright 2004 AWeber Systems, Inc.
var query_string = (location.search) ? ((location.search.indexOf('#') != -1)
? location.search.substring(1, location.search.indexOf('#')) : location.search.substring(1)) : ''; var elements = new Array;

// Load CGI variables into elements[] associative array
if(query_string) {
var pairs = query_string.split("&");
for(i in pairs) {
var tmp = pairs[i].split("=");
elements[unescape(tmp[0])] = unescape(tmp[1]);

// Print one element value indexed by key argument function printElement(key) {
if(elements[key]) {
} else {
// -->

I hope I have included all the information you need.

Jan 14th, 2007, 04:53 AM
Change your input to

<INPUT TYPE="hidden" name="fname" value='<script>printElement(\'custom fname\')</script>'>and see if that works.

Jan 14th, 2007, 06:59 AM
Thanks for the input.
I must be doing something wrong, because with that line copied in, saved and uploaded the page shows two characters;


...at the top of the page where that hidden field is.
It also does not save the variable in the field.

The result for fname = printElement(\

Maybe I will try variations of this line, unless you have another idea.


Jan 14th, 2007, 07:58 AM
I'll think about it some more, but in the meantime, try using " instead of the \' I wrote previously. The idea is that we don't want those apostrophes inside the value statement because the statement itself is enclosed with them. With apostrophes in the middle, it confuses the parser and it thinks the value has come to a premature end.

The \' is called an escape character; it tells the parser that I really want an apostrophe there, and I'm not ending the value statement. I don't know why that didn't work. Anyways, like I said, try " instead and I'll keep thinking about it.

Jan 14th, 2007, 12:37 PM

Main page:


<form method='get' action="Thankyou.html">
<label>Name: <input type='text' size='15' name='name' value='Thomas Jefferson'></label>
<label>Email: <input type='text' size='15' name='lName' value='[email protected]'></label>
<input type='submit' value='Submit'>


<script type="text/javascript">

function processQuery(){

var dataStr = location.search.substring(1,location.search.length).split('&');
var nameStr = dataStr[0].substring(dataStr[0].lastIndexOf('=')+1,dataStr[0].length);
var emailStr = dataStr[1].substring(dataStr[1].lastIndexOf('=')+1,dataStr[1].length);
document.forms[0]['name'].value = nameStr.replace(/\+/g," ");
document.forms[0]['email'].value = emailStr;



<label>Name:<input type='text' name='name' size='30'></label>
<label>Email:<input type='text' name='email' size='15'></label>


Jan 14th, 2007, 06:48 PM
Ancora - thanks for your input. Was this to replace the script I have ?

I added it, in addition to the existing one, and couldn't get it to work.
Maybe I will start from scratch, and just add your script.

I will try that.