473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 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 2493
"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 cannot be good. I thought that storing a...
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 with this code. <head> <script...
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 head of doc I have: <script...
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 make them visible. So I want to add these objects 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(); How can I pass back strings and boolean values from...
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 assembly DLL that was given to me by a co-worker. A...
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 session variables to the next page and when I am...
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 what he called himself!) to do ages ago. I have...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.