View Full Version : Newbie looking for a script to pass information.
mgbparts
09-27-2002, 05:40 PM
I am a newbie with Javascript and I'm looking for a script that will pass text from a simple entry form and insert it into a certain position on a document. I've seen this done on websites, can it be accomplished using Javascript.
Page one where name is inserted in form (text box):
<FORM action=diploma.html method=get>
<P><FONT size=+1>
<CENTER>
<P><FONT color=#dc143c size=4><B>Your Name:</B><BR></FONT><INPUT
name=name>
<P><INPUT type=submit value="Get My Diploma!"></Form>
In this example the name input would be "Tom Smith"
Page two where image appears:
<BODY text=#000000 bgColor=white leftMargin=0 topMargin=0 marginheight="0"
marginwidth="0"><IMG height=732 src="images/diploma.gif" width=575>
<DIV id=Layer10 style="Z-INDEX: 1; LEFT: 105px; WIDTH: 367px; POSITION: absolute; TOP: 318px; HEIGHT: 200px"><DIV align=center width="100"><FONT color=red size=6><B>Tom Smith</B></FONT></DIV>
Thank you in advance for any suggestions or assistance.
ShMiL
09-27-2002, 05:58 PM
I just answered question about the difference between server and client side scripts.
With server side you can do it no problemos chicos!
But using JS (client side) you can only do it in the same page and i'm not certain but I believe you can do it with frames in the same page...
The JS experts will correct me if i'm wrong...
beetle
09-27-2002, 06:02 PM
Here you go, I've highlighted the significant stuff.
test.htm<html>
<head>
<title>test</title>
</HEAD>
<BODY >
<FORM action="temp2.htm" method="get">
<P>
<FONT size=+1>
<CENTER>
<P><FONT color=#dc143c size=4><B>Your Name:</B><BR></FONT>
<INPUT type="text" name="Name">
<P><INPUT type="submit" value="Get My Diploma!"></Form>
</BODY>
</HTML>
test2.htm<html>
<head>
<title>test2</title>
<script>
function parseGetVars() {
var getVars = new Array();
var qString = top.location.search.substring(1);
var pairs = qString.split(/\&/);
for (var i in pairs) {
var nameVal = pairs[i].split(/\=/);
getVars[unescape(nameVal[0])] = unescape(nameVal[1]);
}
return getVars;
}
var g = parseGetVars();
</script>
</head>
<BODY text=#000000 bgColor=white leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
<IMG height=732 src="images/diploma.gif" width=575>
<DIV id=Layer10 style="Z-INDEX: 1; LEFT: 105px; WIDTH: 367px; POSITION: absolute; TOP: 318px; HEIGHT: 200px">
<DIV align=center width="100">
<FONT color=red size=6>
<B><script>document.write(g['Name']);</script></B>
</FONT>
</DIV>
</div>
</body>
</html>
mgbparts
09-27-2002, 06:54 PM
Beetle,
Thank you for the assistance. The script is working well. I Do have a question about someone entering a first name and last name in the form box. When this is done it adds a + sign between the first and last name (Tom+Smith). Is there anything that can be done to eliminate the + sign.
Again thank you for your help.
Bob
mgbparts
ShMiL
09-27-2002, 06:57 PM
beetle
I take off my hat!
I've been web-programming for 4 years and never knew I can pass parameters using JS!
Sorry if I have mistaken someone!
beetle
09-27-2002, 07:09 PM
Originally posted by ShMiL
beetle
I take off my hat!
I've been web-programming for 4 years and never knew I can pass parameters using JS!
Sorry if I have mistaken someone! Why thank you! :o But it's important to understand that the HTML passes the form values via the GET method (no JS here). The JS just handles them on the other side
Cheers :D
ShMiL
09-27-2002, 07:17 PM
I know that :p
Say, it wouldn't work using post method, would it?
beetle
09-27-2002, 07:20 PM
No, javascript cannot access POST data, hence the function name..
function parseGetVars() {
:D
But you can also directly manipulate the seacrh string on a link...
<a href="page.htm?Name=Peter">Link</a>
Or whatever...
whammy
09-28-2002, 01:24 AM
Getting back to the thread, to replace the + signs, just do this:
ASP:
If InStr(1, querystr, "+") Then
querystr = Replace(querystr,"+"," ")
End If
Or in javascript get the querystring from the url and do the same kind of replace:
querystr = querystr.replace(/\+/g,' ');
:D
mgbparts
09-28-2002, 04:04 AM
Whammy,
I'm sorry...I'm not very knowledgeable about Javascript. Are you saying I should be replacing a line in the script that beetle posted for me with:
querystr = querystr.replace(/\+/g,' ');
If so which line of the original script should I be replacing or is this an addition to the script. If an addition, where should I insery it in the script.
Thank you for trying to help and your understanding that I'm not very savy in this area.
Bob
whammy
09-28-2002, 05:33 PM
function parseGetVars() {
var getVars = new Array();
var qString = top.location.search.substring(1);
qString = qString.replace(/\+/g,' ');
var pairs = qString.split(/\&/);
for (var i in pairs) {
var nameVal = pairs[i].split(/\=/);
getVars[unescape(nameVal[0])] = unescape(nameVal[1]);
}
return getVars;
}
var g = parseGetVars();
should work for you...
mgbparts
09-28-2002, 11:38 PM
whammy,
that does correct the problem.
Thank you for your help:D
Bob
whammy
09-29-2002, 12:52 AM
:cool:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.