Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to output data from your last form? 1

Status
Not open for further replies.

RedLion

Programmer
Sep 13, 2000
342
NL
Hello,

I searched everywhere, but I can't find it anywhere. I've got one form where the user can put his info. And an otherside which is there for previewing before posting it to the mail ( .pl) but how can I make the preview page?

<!-- form.htm -->

<html>
<head>
<body>

<form action=&quot;preview.htm&quot; method=&quot;post&quot; name=&quot;myForm&quot;>
<input type=&quot;text&quot; name=&quot;Name&quot; value=&quot;George&quot;>
<input type=&quot;submit&quot;>

</body>
</head>
</html>

<!-- priview.htm -->

<html>
<head>
<body>

Your info to submit:

name:
<script language=&quot;JavaScript&quot;>
document.write(form.myForm.Name.value)
</script>

</body>
</head>
</html>

What am I doing wrong at preview.htm? It seems that I call the form var's not well?

Thanks,

Charl
 
try this:
document.write(document.myForm.Name.value)





nick bulka

 
Sorry Nick, but it's not working!
Some other idea's?

Is it possible to do it only with html?

thanks,
Charl
 
> Is it possible to do it only with html?

Well not exactly. The concept of Form Submission is to send the data to a server side process. However you can bypass this mechanism using client side script in browsers that support it. It would go something like this...

*Hookup a client script handler for myForm.onsubmit event
*build a query string from the form elements
*set the document.location to the URL plus query string
*in the recieving page access the query string using the document.location.search member
*parse the data to obtain all the values

So your old code you posted would look like this:

<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--

function myForm_onsubmit() {

var surl = &quot;clientPreview.htm?name=&quot; +
document.myForm.Name.value;
document.location = surl;
return false; // do not sumbit the form
}

//-->
</SCRIPT>
</HEAD>
<BODY>

<form action=&quot;clientPreview.htm&quot; method=&quot;post&quot; name=&quot;myForm&quot; LANGUAGE=javascript onsubmit=&quot;return myForm_onsubmit()&quot;>
<input type=&quot;text&quot; name=&quot;Name&quot; value=&quot;George&quot;>
<input type=&quot;submit&quot;>
</form>
</body></html>

---- and this

<BODY>

Document.location.search =
<SCRIPT LANGUAGE=javascript>
<!--
var s = document.location.search;
document.writeln( s);
//-->
</SCRIPT>

</BODY>
</HTML>

Hope this helps
-pete
 
Thanks Pete,

That's an other sulotion, but it works and that's the main thing. But an other problem rises with that filtering out the &quot;%20&quot; and replace with &quot; &quot;.

I wrote a little Jscript for it, but it didn't work can you see my error's? Or can it be done a bit more simple?

<!-- preview.htm -->

<html>
<SCRIPT LANGUAGE=javascript>
function getFront(mainStr, searchStr){
foundOffset = mainStr.indexOf(searchStr)
if (foundOffset == -1){
return null
}
return mainStr.substring(0, foundOffset)
}

function getEnd(mainStr, searchStr){
foundOffset = mainStr.indexOf(searchStr)
if (foundOffset == -1){
return null
}
return
mainStr.substring(foundOffset + searchStr.length, mainStr.length)
}

function insertString(mainStr, searchStr, insertStr){
var front = getFront(mainStr, searchStr)
var end = getEnd(mainStr, searchStr)
if (front != null && end != null){
return front + insertStr + searchStr + end
}
return null
}

function deleteString(mainStr, deleteStr){
return replaceString(mainStr, deleteStr, &quot;&quot;)
}

function replaceString(mainStr, searhStr, replaceStr){
var front = getFront(mainStr, searchStr)
var end = getEnd(mainStr, searchStr)
if (front != null && end != null){
return front + replaceStr + end
}
return null
}

</SCRIPT>

<body>
Naam =
<SCRIPT LANGUAGE=javascript>
<!--
var s = document.location.search;
s = replaceString(s, &quot;%20&quot;, &quot; &quot;);
document.writeln( s);
//-->
</SCRIPT>

</BODY>
</HTML>


Thanks Charl
 
Problem is already solved, and yes it can a lot simpler:

<html>
<body>
Naam =
<SCRIPT LANGUAGE=javascript>
<!--
re = /%20/g
var s = document.location.search;
s = s.replace(re, &quot; &quot;);
also = /\?name=/
s = s.replace(also, &quot;&quot;);
document.writeln( s);
//-->
</SCRIPT>
</BODY>
</HTML>

Thanks Pete, you've given a perfect solution, thanks :)

Charl
 
Dear Charl,

Document.location.search =
<SCRIPT LANGUAGE=javascript>
<!--
var s = document.location.search;
document.writeln( s);
document.writeln(&quot;<br>&quot;);
document.writeln( unescape(s));
//-->
</SCRIPT>
 
Pete,

Thanks Pete, on this post I've got an other post, and that is how to do this with two var's?

I've post it on the JavaScript forum (&quot;Howto Cut a URL string in an array?&quot;) , maybe you can help me with that to, it seems to be easy for you with al your nowledge? So please help me than the problem is realy solved? ;-)


Thanks Charl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top