Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-14-2007, 01:23 AM   PM User | #1
goodnabor
New to the CF scene

 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
goodnabor is an unknown quantity at this point
Hidden Input AND Print

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.
Code:
<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.

Code:
<script>printElement("custom fname")</script>
And here is the code in the head to make this work.

Code:
 <script>printElement("email")</script>

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]) {
      document.write(elements[key]);
   } else {
      document.write("Undefined");
   }
}
// -->
</script>
I hope I have included all the information you need.
goodnabor is offline   Reply With Quote
Old 01-14-2007, 03:53 AM   PM User | #2
TripperTreats
New Coder

 
TripperTreats's Avatar
 
Join Date: Oct 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
TripperTreats is an unknown quantity at this point
Change your input to

Code:
 <INPUT TYPE="hidden" name="fname" value='<script>printElement(\'custom fname\')</script>'>
and see if that works.
__________________
Psychedelic digital art at www.trippertreats.com.

"And in the end, the love you take
is equal to the love you make
."
TripperTreats is offline   Reply With Quote
Old 01-14-2007, 05:59 AM   PM User | #3
goodnabor
New to the CF scene

 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
goodnabor is an unknown quantity at this point
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.

Thanks.
goodnabor is offline   Reply With Quote
Old 01-14-2007, 06:58 AM   PM User | #4
TripperTreats
New Coder

 
TripperTreats's Avatar
 
Join Date: Oct 2006
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
TripperTreats is an unknown quantity at this point
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.
__________________
Psychedelic digital art at www.trippertreats.com.

"And in the end, the love you take
is equal to the love you make
."
TripperTreats is offline   Reply With Quote
Old 01-14-2007, 11:37 AM   PM User | #5
Ancora
Banned

 
Join Date: Oct 2005
Location: I'm in GMT -5
Posts: 314
Thanks: 0
Thanked 1 Time in 1 Post
Ancora is on a distinguished road
goodnabor:

Main page:

Code:
<html>
<head>

</head>
<body>
	<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='tj@usa.gov'></label>
		<input type='submit' value='Submit'>
	</form>
</body>
</html>
Thankyou.html:

Code:
<html>
<head>
<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;
	}

	onload=processQuery;

</script>
</head>
<body>

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

</body>
</html>
Ancora is offline   Reply With Quote
Old 01-14-2007, 05:48 PM   PM User | #6
goodnabor
New to the CF scene

 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
goodnabor is an unknown quantity at this point
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.
goodnabor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:04 PM.


Advertisement
Log in to turn off these ads.