By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,395 Members | 2,537 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,395 IT Pros & Developers. It's quick & easy.

Help passing variables from forms

P: n/a
**** 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
Share this Question
Share on Google+
2 Replies


P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.