Help passing variables from forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard

    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="JavaS cript"><!--
    function generateForm()
    {

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

    parent.self.doc ument.open();
    parent.self.doc ument.writeln(" <CENTER>");
    parent.self.doc ument.writeln(" <TABLE CELLSPACING=\"0 \"
    CELLPADDING=\"0 \"BORDER=\"1 \" WIDTH=\"95%\">< TR><TD ALIGN=\"left\"> ");


    //What to write//
    parent.self.doc ument.writeln(" <FONT FACE=\"verdana, arial,helvetica l\">Info1
    <B>" + info1 + "</B></FONT><BR>");

    parent.self.doc ument.writeln(" <FONT FACE=\"verdana, arial,helvetica l\">Info2
    <B>" + info2 + "</B></FONT><BR>");


    parent.self.doc ument.writeln(" <FONT FACE=\"verdana, arial,helvetica l\">Info3
    <B>" + info3 + "</B></FONT><BR>");

    parent.self.doc ument.writeln(" <FONT FACE=\"verdana, arial,helvetica l\">Info4
    <B>" + info4 + "</B></FONT><BR>");


    parent.self.doc ument.writeln(" </TD></TR></TABLE>");
    parent.self.doc ument.writeln(" </CENTER>");
    parent.self.doc ument.close();
    }

    //--></SCRIPT>

    </HEAD>
    <BODY BGCOLOR="#FFFFF F">
    <CENTER>
    <TABLE CELLSPACING=10 CELLPADDING=0 BORDER=1 WIDTH=95%>
    <TR><TD COLSPAN="2" ALIGN="center" BGCOLOR="#99FFC C"><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;&nbs p;<INPUT TYPE="text" NAME="myinfo" SIZE="30"
    VALUE="">
    <BR>
    Input Info2 Here:&nbsp;&nbs p;<INPUT TYPE="text" NAME="myinfo2" SIZE="30"
    VALUE="">
    <BR>
    Input Info3 Here:&nbsp;&nbs p;<INPUT TYPE="text" NAME="myinfo3" SIZE="30"
    VALUE="">
    <BR>
    Input Info4 Here:&nbsp;&nbs p;<INPUT TYPE="text" NAME="myinfo4" SIZE="30"
    VALUE="">
    <BR>
    <BR><INPUT TYPE="button" VALUE="Generate " onClick="genera teForm()">
    </FORM>
    </TD>
    </FORM>
    </TR>
    </TABLE>
    </CENTER>
    </BODY>
    </HTML>



    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    *** Usenet.com - The #1 Usenet Newsgroup Service on The Planet! ***
    Best Usenet Service Providers 2025 ranked by Newsgroup Access Newsservers, Usenet Search, Features & Free Trial. Add VPN for privacy.

    Unlimited Download - 19 Seperate Servers - 90,000 groups - Uncensored
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  • McKirahan

    #2
    Re: Help passing variables from forms

    "Richard" <richard@go.com > wrote in message news:3fe47d89@p ost.usenet.com. ..[color=blue]
    > **** 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[/color]
    page[color=blue]
    > 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[/color]
    (a[color=blue]
    > 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="JavaS cript"><!--
    > function generateForm()
    > {
    >
    > //Input from FORM FIELDS//
    > info1 = this.document.f orms[0].myinfo.value;
    > info2 = this.document.f orms[0].myinfo2.value;
    > info3 = this.document.f orms[0].myinfo3.value;
    > info4 = this.document.f orms[0].myinfo4.value;
    >
    > parent.self.doc ument.open();
    > parent.self.doc ument.writeln(" <CENTER>");
    > parent.self.doc ument.writeln(" <TABLE CELLSPACING=\"0 \"
    > CELLPADDING=\"0 \"BORDER=\"1 \" WIDTH=\"95%\">< TR><TD ALIGN=\"left\"> ");
    >
    >
    > //What to write//
    > parent.self.doc ument.writeln(" <FONT[/color]
    FACE=\"verdana, arial,helvetica l\">Info1[color=blue]
    > <B>" + info1 + "</B></FONT><BR>");
    >
    > parent.self.doc ument.writeln(" <FONT[/color]
    FACE=\"verdana, arial,helvetica l\">Info2[color=blue]
    > <B>" + info2 + "</B></FONT><BR>");
    >
    >
    > parent.self.doc ument.writeln(" <FONT[/color]
    FACE=\"verdana, arial,helvetica l\">Info3[color=blue]
    > <B>" + info3 + "</B></FONT><BR>");
    >
    > parent.self.doc ument.writeln(" <FONT[/color]
    FACE=\"verdana, arial,helvetica l\">Info4[color=blue]
    > <B>" + info4 + "</B></FONT><BR>");
    >
    >
    > parent.self.doc ument.writeln(" </TD></TR></TABLE>");
    > parent.self.doc ument.writeln(" </CENTER>");
    > parent.self.doc ument.close();
    > }
    >
    > //--></SCRIPT>
    >
    > </HEAD>
    > <BODY BGCOLOR="#FFFFF F">
    > <CENTER>
    > <TABLE CELLSPACING=10 CELLPADDING=0 BORDER=1 WIDTH=95%>
    > <TR><TD COLSPAN="2" ALIGN="center" BGCOLOR="#99FFC C"><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;&nbs p;<INPUT TYPE="text" NAME="myinfo" SIZE="30"
    > VALUE="">
    > <BR>
    > Input Info2 Here:&nbsp;&nbs p;<INPUT TYPE="text" NAME="myinfo2" SIZE="30"
    > VALUE="">
    > <BR>
    > Input Info3 Here:&nbsp;&nbs p;<INPUT TYPE="text" NAME="myinfo3" SIZE="30"
    > VALUE="">
    > <BR>
    > Input Info4 Here:&nbsp;&nbs p;<INPUT TYPE="text" NAME="myinfo4" SIZE="30"
    > VALUE="">
    > <BR>
    > <BR><INPUT TYPE="button" VALUE="Generate " onClick="genera teForm()">
    > </FORM>
    > </TD>
    > </FORM>
    > </TR>
    > </TABLE>
    > </CENTER>
    > </BODY>
    > </HTML>[/color]

    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="JavaS cript">
    <!--
    function generateForm() {
    var form = document.forms[0];
    var valu = new Array();
    valu[1] = form.myinfo1.va lue;
    valu[2] = form.myinfo2.va lue;
    valu[3] = form.myinfo3.va lue;
    valu[4] = form.myinfo4.va lue;
    if (form.myinfo5.c hecked) {
    valu[5] = form.myinfo5.va lue;
    } else {
    valu[5] = "";
    }
    if (form.myinfo6.c hecked) {
    valu[6] = form.myinfo6.va lue;
    } else {
    valu[6] = "";
    }
    valu[7] = form.myinfo7.op tions[form.myinfo7.se lectedIndex].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="#FFFFF F">
    <CENTER>
    <TABLE BORDER='1' CELLPADDING='10 ' CELLSPACING='10 ' WIDTH='95%'>
    <TR>
    <TD COLSPAN="2" ALIGN="center" BGCOLOR="#99FFC C">
    <FONT SIZE=+2 FACE="trebuchet ms">Info Template</FONT>
    </TD>
    </TR>
    <TR>
    <TD ALIGN="left">
    <!--Form Input Fields--!>
    <FORM NAME="myForm" onSubmit="retur n 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>


    Comment

    • Evertjan.

      #3
      Re: Help passing variables from forms

      Richard wrote on 20 dec 2003 in comp.lang.javas cript:[color=blue]
      > info4 = this.document.f orms[0].myinfo4.value;
      >[/color]

      <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)

      Comment

      Working...