faqts : Computers : Programming : Languages : JavaScript : Forms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

25 of 48 people (52%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

How can I pass one hidden form value into a new form on a second page, and then post all values onto a third form on a new page?

Dec 13th, 2000 13:04
Delf Burkhardt, Rob Suisted,


I'll show you the two steps,
works on NS 4.5++, IE4++

you have to create two html-files, 
called step_1.html and step_2.html:


<html>
<head>
	<title>submit</title>
</head>

<body>
<form action="step_2.html">
<input type="hidden" value="topsecret" name="hiddenfield"><br>
<input type="submit" value="submit">

</form>

</body>
</html>




// 2nd html-file starts here:



<html>
<head>
	<title>Answer-Form</title>

<script language="JavaScript">
<!--
//
var esc = unescape(location.search);
var ss = esc.substring(1,esc.length);
var ok = false;
var myTitle=new Array();
var myContent= new Array();
var cur="";

if(ss.length!=0){
    ok=true; 
	ss= unescape(ss);
    str=ss.split('&');
	for (var i=0; i<str.length;i++){
		cur=str[i].split('=');
		if (cur.length==2){
			myTitle[i]=cur[0];
			myContent[i]=cur[1];		
		}
		else{
			myTitle[i]="";
			myContent[i]=cur[0];	
		}
	}
}

function init(){
	for(var i=0;i<myTitle.length;i++){
		if(myTitle[i]=="hiddenfield"){
			document.forms[0].showfield.value=myContent[i];
			break;
		}
	} 
}

//-->
</script>
</head>

<body onload="init()">
<form action="step_1.html">
<input type="text" value="" size="30" name="showfield"><br>
<input type="submit" value="submit"><br>
</form>

</body>
</html>