472,337 Members | 1,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,337 software developers and data experts.

Help passing variables from forms

**** Post for FREE via your newsreader at post.usenet.com ****

HI,

I am working on a project where I need to input data to a (local) HTML page
using multiple form elements, such as text, radio, checkbox, and dropdown.
When the form Submit button is clicked, I then need the input data either
written to another location on the same page, or written to another page (a
different frame would be fine)

This is to be used as a template where someone can enter data, generate an
output, and then copy and paste that output into another application.

An example of what I am working on is below.

I can get exactly what I want using text input only, but passing the
variables from other elements is killing me.

Any help would be GREATLY appreciated.

<HTML>
<HEAD>

<SCRIPT language="JavaScript"><!--
function generateForm()
{

//Input from FORM FIELDS//
info1 = this.document.forms[0].myinfo.value;
info2 = this.document.forms[0].myinfo2.value;
info3 = this.document.forms[0].myinfo3.value;
info4 = this.document.forms[0].myinfo4.value;

parent.self.document.open();
parent.self.document.writeln("<CENTER>");
parent.self.document.writeln("<TABLE CELLSPACING=\"0\"
CELLPADDING=\"0\"BORDER=\"1\" WIDTH=\"95%\"><TR><TD ALIGN=\"left\">");
//What to write//
parent.self.document.writeln("<FONT FACE=\"verdana,arial,helvetical\">Info1
<B>" + info1 + "</B></FONT><BR>");

parent.self.document.writeln("<FONT FACE=\"verdana,arial,helvetical\">Info2
<B>" + info2 + "</B></FONT><BR>");
parent.self.document.writeln("<FONT FACE=\"verdana,arial,helvetical\">Info3
<B>" + info3 + "</B></FONT><BR>");

parent.self.document.writeln("<FONT FACE=\"verdana,arial,helvetical\">Info4
<B>" + info4 + "</B></FONT><BR>");
parent.self.document.writeln("</TD></TR></TABLE>");
parent.self.document.writeln("</CENTER>");
parent.self.document.close();
}

//--></SCRIPT>

</HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER>
<TABLE CELLSPACING=10 CELLPADDING=0 BORDER=1 WIDTH=95%>
<TR><TD COLSPAN="2" ALIGN="center" BGCOLOR="#99FFCC"><FONT SIZE=+2
FACE="trebuchet ms">Info Template</FONT></TD></TR>
<TR>
<TD ALIGN="left">
<!--Form Input Fields--!>
<FORM NAME="myForm">
Input Info1 Here:&nbsp;&nbsp;<INPUT TYPE="text" NAME="myinfo" SIZE="30"
VALUE="">
<BR>
Input Info2 Here:&nbsp;&nbsp;<INPUT TYPE="text" NAME="myinfo2" SIZE="30"
VALUE="">
<BR>
Input Info3 Here:&nbsp;&nbsp;<INPUT TYPE="text" NAME="myinfo3" SIZE="30"
VALUE="">
<BR>
Input Info4 Here:&nbsp;&nbsp;<INPUT TYPE="text" NAME="myinfo4" SIZE="30"
VALUE="">
<BR>
<BR><INPUT TYPE="button" VALUE="Generate" onClick="generateForm()">
</FORM>
</TD>
</FORM>
</TR>
</TABLE>
</CENTER>
</BODY>
</HTML>

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*** Usenet.com - The #1 Usenet Newsgroup Service on The Planet! ***
http://www.usenet.com
Unlimited Download - 19 Seperate Servers - 90,000 groups - Uncensored
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Jul 20 '05 #1
2 2358
"Richard" <ri*****@go.com> wrote in message news:3f******@post.usenet.com...
**** Post for FREE via your newsreader at post.usenet.com ****

HI,

I am working on a project where I need to input data to a (local) HTML page using multiple form elements, such as text, radio, checkbox, and dropdown.
When the form Submit button is clicked, I then need the input data either
written to another location on the same page, or written to another page (a different frame would be fine)

This is to be used as a template where someone can enter data, generate an
output, and then copy and paste that output into another application.

An example of what I am working on is below.

I can get exactly what I want using text input only, but passing the
variables from other elements is killing me.

Any help would be GREATLY appreciated.

<HTML>
<HEAD>

<SCRIPT language="JavaScript"><!--
function generateForm()
{

//Input from FORM FIELDS//
info1 = this.document.forms[0].myinfo.value;
info2 = this.document.forms[0].myinfo2.value;
info3 = this.document.forms[0].myinfo3.value;
info4 = this.document.forms[0].myinfo4.value;

parent.self.document.open();
parent.self.document.writeln("<CENTER>");
parent.self.document.writeln("<TABLE CELLSPACING=\"0\"
CELLPADDING=\"0\"BORDER=\"1\" WIDTH=\"95%\"><TR><TD ALIGN=\"left\">");
//What to write//
parent.self.document.writeln("<FONT FACE=\"verdana,arial,helvetical\">Info1 <B>" + info1 + "</B></FONT><BR>");

parent.self.document.writeln("<FONT FACE=\"verdana,arial,helvetical\">Info2 <B>" + info2 + "</B></FONT><BR>");
parent.self.document.writeln("<FONT FACE=\"verdana,arial,helvetical\">Info3 <B>" + info3 + "</B></FONT><BR>");

parent.self.document.writeln("<FONT FACE=\"verdana,arial,helvetical\">Info4 <B>" + info4 + "</B></FONT><BR>");
parent.self.document.writeln("</TD></TR></TABLE>");
parent.self.document.writeln("</CENTER>");
parent.self.document.close();
}

//--></SCRIPT>

</HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER>
<TABLE CELLSPACING=10 CELLPADDING=0 BORDER=1 WIDTH=95%>
<TR><TD COLSPAN="2" ALIGN="center" BGCOLOR="#99FFCC"><FONT SIZE=+2
FACE="trebuchet ms">Info Template</FONT></TD></TR>
<TR>
<TD ALIGN="left">
<!--Form Input Fields--!>
<FORM NAME="myForm">
Input Info1 Here:&nbsp;&nbsp;<INPUT TYPE="text" NAME="myinfo" SIZE="30"
VALUE="">
<BR>
Input Info2 Here:&nbsp;&nbsp;<INPUT TYPE="text" NAME="myinfo2" SIZE="30"
VALUE="">
<BR>
Input Info3 Here:&nbsp;&nbsp;<INPUT TYPE="text" NAME="myinfo3" SIZE="30"
VALUE="">
<BR>
Input Info4 Here:&nbsp;&nbsp;<INPUT TYPE="text" NAME="myinfo4" SIZE="30"
VALUE="">
<BR>
<BR><INPUT TYPE="button" VALUE="Generate" onClick="generateForm()">
</FORM>
</TD>
</FORM>
</TR>
</TABLE>
</CENTER>
</BODY>
</HTML>


a) You have an extra " </FORM>" tag.

b) What font is "helvetical"?

c) You could use an apostrophe instead of: \".

d) You could save a bunch coding using a style sheet.

e) Will this variation of your code help you?

Watch for word-wrap. Test as-is.
<HTML>
<HEAD>
<title>generate.htm</title>
<SCRIPT language="JavaScript">
<!--
function generateForm() {
var form = document.forms[0];
var valu = new Array();
valu[1] = form.myinfo1.value;
valu[2] = form.myinfo2.value;
valu[3] = form.myinfo3.value;
valu[4] = form.myinfo4.value;
if (form.myinfo5.checked) {
valu[5] = form.myinfo5.value;
} else {
valu[5] = "";
}
if (form.myinfo6.checked) {
valu[6] = form.myinfo6.value;
} else {
valu[6] = "";
}
valu[7] = form.myinfo7.options[form.myinfo7.selectedIndex].value;
var html = "<CENTER>";
html += "<TABLE BORDER='1' CELLPADDING='0' CELLSPACING='0'
WIDTH='95%'>";
html += "<TR>";
html += " <TD>";
html += " Info1 : <B>" + valu[1] + "</B><BR>";
html += " Info2 : <B>" + valu[2] + "</B><BR>";
html += " Info3 : <B>" + valu[3] + "</B><BR>";
html += " Info4 : <B>" + valu[4] + "</B><BR>";
html += " Info5 : <B>" + valu[5] + "</B><BR>";
html += " Info6 : <B>" + valu[6] + "</B><BR>";
html += " Info7 : <B>" + valu[7] + "</B><BR>";
html += " </TD>";
html += "</TR>";
html += "</TABLE>";
html += "</CENTER>";
document.write(html);
return true;
}
//-->
</SCRIPT>
<style type="text/css">
td { font-family:verdana,arial,helvetica }
</style>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER>
<TABLE BORDER='1' CELLPADDING='10' CELLSPACING='10' WIDTH='95%'>
<TR>
<TD COLSPAN="2" ALIGN="center" BGCOLOR="#99FFCC">
<FONT SIZE=+2 FACE="trebuchet ms">Info Template</FONT>
</TD>
</TR>
<TR>
<TD ALIGN="left">
<!--Form Input Fields--!>
<FORM NAME="myForm" onSubmit="return generateForm()">
Input Info1 Here: &nbsp; <INPUT TYPE="text" NAME="myinfo1" SIZE="30"
VALUE="1">
<BR>
Input Info2 Here: &nbsp; <INPUT TYPE="text" NAME="myinfo2" SIZE="30"
VALUE="2">
<BR>
Input Info3 Here: &nbsp; <INPUT TYPE="text" NAME="myinfo3" SIZE="30"
VALUE="3">
<BR>
Input Info4 Here: &nbsp; <INPUT TYPE="text" NAME="myinfo4" SIZE="30"
VALUE="4">
<BR>
Input Info5 Here: &nbsp; <INPUT TYPE="checkbox" NAME="myinfo5"
VALUE="5">
<BR>
Input Info6 Here: &nbsp; <INPUT TYPE="radio" NAME="myinfo6" VALUE="6">
<BR>
Input Info7 Here: &nbsp; <SELECT NAME="myinfo7"><OPTION VALUE="
"><OPTION VALUE="7"></SELECT>
<BR>
<BR><INPUT TYPE="submit" VALUE="Generate"> &nbsp; <INPUT TYPE="reset"
VALUE="Reset">
</FORM>
</TD>
</TR>
</TABLE>
</CENTER>
</BODY>
</HTML>
Jul 20 '05 #2
Richard wrote on 20 dec 2003 in comp.lang.javascript:
info4 = this.document.forms[0].myinfo4.value;


<form>
....
<input type='radio' name='ra' value='r1'>R1
<input type='radio' name='ra' value='r2'>R2
</form>

x = document.forms[0]
info1 = x.myinfo1.value
info2 = x.myinfo2.value
info3 = x.myinfo3.value
info4 = x.myinfo4.value

function z(){
info5='none'
for (i=0;i<2;i++)
if(x.ra[i].checked)info5=x.ra[i].value;
}

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jason Us | last post by:
Does anyone have experience with passing variables from an ASP page to a JSP page. The way it currently works in passing the SSN in the URL. This...
2
by: Ed | last post by:
I need to know how to pass variables because I want to use the same function to varify multiple data imput boxes. Please tell me what's wrong...
9
by: Max | last post by:
I'm new with Javascript and can't seem to figure out what I'm doing wrong here as I'm not able to pass a simple variable to a function. In the...
3
by: SV | last post by:
Dear all, In my application I have a lot of hidden fields. I want to make them invisible for the users though for debugging reasons I want to...
2
by: Michael C | last post by:
What's the best wat to pass data between two separate forms. For instance, Form1 invokes Form2 like this: Form z = new Form2(); z.Show(); ...
6
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an...
4
by: DOTNET | last post by:
Hi, Anybody help me regarding this error: I am assigning the values to the session variables when the button is clicked and passing these...
7
by: The Doctor | last post by:
A rather elementary question, In VB5, how can I pass a variable from one form to another?
2
by: deshg | last post by:
Hey everyone, I am a php programmer originally and am just helping a friend of mine update their website that they paid a designer (well that's...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.