SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Classic ASP to MSWord

    I have an HTML form that sends data to a Classic ASP which generates and formats an MS Word document with the form data. There is a JavaScript on the HTML page that allows an additional text field to be displayed if a checkbox is checked.


    Problem #1:
    I am receiving a value of "ON" in addition to the value I want to have displayed. I assume that is from the checkbox being active. I don't know how to only show the data from the field.

    Problem #2:
    One of my fields is showing a value of "False" without any of the form data.
    I don't see anything wrong with my code but maybe I just need another set of eyes to look at it.

    I've added some code to validate what information is being passed from the form and everything shows up in that code in the Document. Can't figure this one out.

    Please see screen shot of MS Word output -- Attached zip file.

    Here is the code for my form:


    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
      <title>New Client Doc</title>
      <style>   span {
                      background:#def3ca; padding:3px; float:left;
                      }
                td.txt {
                         font-family:arial narrow;
                         font-size:11pt;
                         }
      </style>
      <script type="text/javascript" src="scripts/usableforms.js"></script>
      <!--
      Written by: Brian Salvitti
                       5/23/2011//-->
    
      <script src="scripts/jquery-latest.js"></script>
    </head>
    <body topmargin=0 leftmargin=0>
    <!--#### Create Banner Image//-->
    <p align=center><img src=images/banner.jpg></p>
    <!--#### End Banner Image//-->
    <!--#### Create Main Table//-->
      <table align=center width="650" border="1">
      <tr>
       <!-- ##### Create toolbar images //-->
          <td width=650 colspan=3 align=right><a href=admin.asp target=_blank><img src=images/admin.png border=0 alt="Administration"></a>
          &nbsp;
          &nbsp;
          <a href=#><img src=images/printer.jpg border=0 alt="Print This Page" onClick="window.print()"></a>
          &nbsp;
          &nbsp;
          <a href=edit.asp target=_blank><img src=images/report.png border=0 alt="Edit Document"></a>
          &nbsp;
          &nbsp;
          <a href=help.html target=_blank><img src=images/help.png border=0 alt="Before You Begin"></a>
            </td>
       <!--##### End of Toolbar images //-->
      <tr>
    		 <td colspan=3 align=center>
      <!--#### Begin Form//-->
    		 <form action="createclientdoc.asp" method="post">
    		 <strong><font face="Arial Narrow" size="4">Contacts Table</font></strong>
                </td>
      </tr>
      <tr>
            <td align="right" class=txt>New Client Acronym: <input name="newclienttxt">
     <!--#### Begin Upper Case Conversion Script (This continues for each TEXT field throughout the form) //-->
            <script>
    		  $('input').bind('blur', function() {
    		    $(this).val(function(i, val) {
    		      return val.toUpperCase();
    		    });
    		  });
    		  </script>
    <!--#### End Of Upper Case Script //-->
            </td>
               <td align="right" >&nbsp;</td>
               <td>&nbsp;</td>
      </tr>
      <tr>
                <td align="right" class=txt>Tech Support Rep(s): <input name="techreptxt">
                <script>
    		  $('input').bind('blur', function() {
    		    $(this).val(function(i, val) {
    		      return val.toUpperCase();
    		    });
    		  });
    		  </script>
    		   </td>
                <td align="right" class=txt>Phone: <input type=text name=techphone></td>
                <td class=txt>Add Rep <input type="checkbox" rel="addrep" name="addrep" id="addrep" /></td>
      <!-- ******* Display additional Tech field //-->
    <tr rel="addrep">
    	       <td class=txt align=right align=right><label for="addrep">
    		          <span class="accessibility"></span> <font color=red>TS Backup:</font></label>
    	                  <input name="addrep" id="addrep" /></td>
    	       <td align=right class=txt><font color=red>Phone:</font> <input type=text name="bkrepphone"></td>
    </tr>
     <!-- ****** End additional Tech field //-->
      </tr>
       <tr>
                 <td align="right" class=txt>DBA: <input name="dbatxt">
                   <script>
    		  $('input').bind('blur', function() {
    		    $(this).val(function(i, val) {
    		      return val.toUpperCase();
    		    });
    		  });
    		  </script>
    		  </td>
                 <td align="right" class=txt>Phone: <input type=text name=dbaphone></td>
                 <td class=txt>&nbsp; </td>
      </tr>
      <tr>
                 <td align="right" class=txt>SQE: <input name="sqetxt">
                  <script>
    			 		  $('input').bind('blur', function() {
    			 		    $(this).val(function(i, val) {
    			 		      return val.toUpperCase();
    			 		    });
    			 		  });
    		  </script>
                 </td>
                 <td align="right" class=txt>Phone: <input type=text name=sqephone></td>
                 <td class=txt>&nbsp;</td>
      </tr>
      <tr>
                 <td align="right" >&nbsp;</td>
                 <td align="right" >&nbsp;</td>
                 <td>&nbsp;</td>
      </tr>
      <tr>
                <td align="right">&nbsp;</td>
                <td align="right" colspan="2">&nbsp;</td>
      </tr>
      <tr>
                 <td align="center" colspan=3><font face="Arial Narrow" size="4"><strong>Site Contacts</strong></font></td>
      </tr>
      <tr>
                 <td align="right"class=txt>Site Contacts: <input name="sitecontactstxt">
                  <script>
    			 		  $('input').bind('blur', function() {
    			 		    $(this).val(function(i, val) {
    			 		      return val.toUpperCase();
    			 		    });
    			 		  });
    		  </script>
                </td>
                 <td align="right" class=txt>Phone: <input type=text name=sitecontactphone></td>
      </tr>
      <tr>
                 <td align="right">&nbsp;</td>
      </tr>
      <tr>
                  <td align="right" class=txt>Alineo Version: <input name="softwareinfotxt">
                   <script>
    			  		  $('input').bind('blur', function() {
    			  		    $(this).val(function(i, val) {
    			  		      return val.toUpperCase();
    			  		    });
    			  		  });
    		  </script>
                  </td>
                  <td align="right" colspan="2">&nbsp;</td>
      </tr>
      <tr>
                  <td align="right"></td>
                  <td align="right" colspan="2"><input type="submit" value="Create Client Doc"></td>
      </tr>
             </form>
       </table>
    </body>
    </html>

    *****Here is the code for my ASP page:


    Code ASP:
    <%
     
    OPTION EXPLICIT
     
    ' Waits until all the asp is done before dumping the text to the browser
    response.buffer = true
     
     
    'Receiving values from Form, assign the values entered to variables
    'Set a new variable for each new field added
     
    DIM newclient
    newclient=Request.Form("newclienttxt")   'Define Variable For New Client Acronym
     
    DIM tech
       tech=Request.Form("techreptxt")       'Define Variable For Tech Support Field
     
    DIM techph
     techph=Request.Form("techphone")        'Define Variable For Tech Support Phone
     
    DIM tsbk
       tsbk=Request.Form("addrep")           'Define Variable For Additional Tech Rep
     
    DIM bkrepph
    bkrepph=Request.Form=("bkrepphone")      'Define Variable For Additional Tech Phone
     
    DIM sqeph
      sqeph=Request.Form("sqephone")         'Define Variable For SQE Phone
     
    DIM dba
        dba=Request.Form("dbatxt")           'Define Variable For DBA
     
    DIM dbaph
      dbaph=Request.Form("dbaphone")         'Define Variable For DBA Phone
     
    DIM sitecontact
     sitecontact=Request.Form("sitecontactstxt")   'Define Variable For Site Contact
     
    DIM sitecontactph
     sitecontactph=Request.Form("sitecontactphone")'Define Variable For Site Contact Phone
     
    DIM softwareinfo
    softwareinfo=Request.Form("softwareinfotxt")   'Define Variable For Software
     
     
    ' Tells the browser to open word
    Response.ContentType = "application/vnd.ms-word"
    ' Adds a header to give the document a name
    response.AddHeader "content-disposition", "inline;filename=client.doc"
     
    %>
     
    <html>
    <head>
      <title></title>
      <meta content="Evrsoft First Page" name="GENERATOR">
    <style type="text/css">
    .title {
    	FONT-SIZE: 15pt; COLOR: blue; FONT-FAMILY: arial; BACKGROUND-COLOR: #dddddd
    }
    .txt {
    	FONT-SIZE: 25pt; COLOR: black; FONT-FAMILY: tahoma
    }
    TD.maintxt {
    	FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: arial narrow
    }
    TD.subhead {
    	FONT-SIZE: 15pt; COLOR: black; FONT-FAMILY: arial narrow
    }
    </style>
    </head>
     
    <body>
      <table width="550" align="center" border="1">
        <tbody>
          <tr>
            <td class="title" align="middle" colspan="2" span=""><%response.Write(newclient)%> Client Document</td>
          </tr>
     
          <tr>
            <td class="subhead" width="246">MEDecision Contact Information</td>
     
            <td width="290"></td>
          </tr>
     
          <tr>
            <td class="maintxt" width="248">Tech Support Rep: <%response.Write(tech)%></td>
     
            <td class="maintxt" width="290">Phone: <%response.write(techph)%></td>
          </tr>
     
          <tr>
            <td class="maintxt">TS Backup:<%Response.Write(tsbk)%></td>
            <td class="maintxt">Phone:    <%Response.Write(bkrepph)%> </td>
         <tr>
            <td class="maintxt">Database Admin: <%Response.Write(dba)%></td>
            <td class="maintxt">Phone:<%response.write(dbaph)%></td>
         <tr>
            <td class="maintxt>Phone:
          </tr>
          <tr>
            <td class="maintxt" width="248">Site Contact: <%Response.Write(sitecontact)%></td>
     
            <td class="maintxt" width="290">Phone:<%Response.Write(sitecontactph)%></td>
          </tr>
     
          <tr>
            <td class="maintxt" width="248"></td>
     
            <td width="290"></td>
          </tr>
     
          <tr>
            <td class="maintxt" width="248"></td>
     
            <td width="290"></td>
          </tr>
     
      </table>
      <%
     
     
    <!-- This code is for testing which variables are being passed from the form. Take out when in PRODUCTION  //-->
     
      ' Check to see if any querystring varibles exist
     
     
      if len (request.servervariables("query_string")) >1 then %>
      <b>Variables passed via QueryString</b><br>
      <!-- The following was passed via a form with a method equal to get, a hyperlink, or
      a form action with written varibles -->
     
      <%
     
      Dim variable_name
      Dim variable_value
     
      'Loop to find each querystring variable name and varible value
     
      for each variable_name in request.querystring
      variable_value=request.querystring(variable_name)
     
      'If there is a querystring variable name and value inputted then write it also
      response.write variable_name &" = "
      response.write variable_value &"<br>" &chr(13)
      next
     
      ' end for next loop for all querystrings
      end if
     
      ' end check for querstring values
     
      ' Check to see if any form varibles exist
      if len(request.form) > 0 then %>
     
      <p>
     
      <b>Variables passed via Post</b><br>
     
      <!-- The following was passed via a form with a method equal to post -->
     
      <%
      'Loop to find each variable name and varible value
     
     
      for each variable_name in request.form
      variable_value=request.form(variable_name)
     
      'If there is a variable name and value inputted then write it also
      response.write variable_name &" = "
      response.write variable_value &" <br>" &chr(13)
      next ' end for next loop for all
      end if ' end check for form values
    %>
    </body>
    </html>
    Attached Files Attached Files
    Last edited by Mittineague; May 26, 2011 at 16:12. Reason: reformatting bbcode tags

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Please edit your post to remove unnecessary line breaks and to put the code between [ code][/code] tags. (Remove the space between [ and code. I put it there so you could see the tags).
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't seem to have the EDIT option available to me.

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    So you'll have to repost then.

    As it stands the code is too difficult to follow. If you use the code tags it will retain any spacing too.
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have an HTML form that sends data to a Classic ASP which generates and formats an MS Word document with the form data. There is a JavaScript on the HTML page that allows an additional text field to be displayed if a checkbox is checked.

    Problem #1:
    I am receiving a value of "ON" in addition to the value I want to have displayed. I assume that is from the checkbox being active. I don't know how to only show the data from the field.

    Problem #2:
    One of my fields is showing a value of "False" without any of the form data.
    I don't see anything wrong with my code but maybe I just need another set of eyes to look at it.

    I've added some code to validate what information is being passed from the form and everything shows up in that code in the Document. Can't figure this one out.

    Please see screen shot of MS Word output -- Attached zip file.

    Here is the code for my form:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <html>
    <head>
    
    <title>New Client Doc</title>
    
    <style> span {
    background:#def3ca; padding:3px; float:left;
    }
    
    td.txt {
    font-family:arial narrow;
    font-size:11pt;
    }
    </style>
    
    <script type="text/javascript" src="scripts/usableforms.js"></script>
    
    <script src="scripts/jquery-latest.js"></script>
    </head>
    <body topmargin=0 leftmargin=0>
    
    <!--#### Create Banner Image//-->
    
    <p align=center><img src=images/banner.jpg></p>
    
    <!--#### End Banner Image//-->
    
    
    <!--#### Create Main Table//-->
    
    <table align=center width="650" border="1">
    <tr>
    
    <!-- ##### Create toolbar images //-->
    
    <td width=650 colspan=3 align=right><a href=admin.asp target=_blank><img src=images/admin.png border=0 alt="Administration"></a>
    
    &nbsp;
    &nbsp;
    
    <a href=#><img src=images/printer.jpg border=0 alt="Print This Page" onClick="window.print()"></a>
    
    &nbsp;
    &nbsp;
    
    <a href=edit.asp target=_blank><img src=images/report.png border=0 alt="Edit Document"></a>
    
    &nbsp;
    &nbsp;
    
    <a href=help.html target=_blank><img src=images/help.png border=0 alt="Before You Begin"></a>
    </td>
    
    <!--##### End of Toolbar images //-->
    
    <tr>
    
    <td colspan=3 align=center>
    
    <!--#### Begin Form//-->
    
    <form action="createclientdoc.asp" method="post">
    
    <strong><font face="Arial Narrow" size="4">Contacts Table</font></strong>
    </td>
    
    </tr>
    
    <tr>
    <td align="right" class=txt>New Client Acronym: <input name="newclienttxt">
    
    <!--#### Begin Upper Case Conversion Script (This continues for each TEXT field throughout the form) //-->
    
    <script>
    $('input').bind('blur', function() {
    
    $(this).val(function(i, val) {
    return val.toUpperCase();
    });
    
    });
    </script>
    
    
    <!--#### End Of Upper Case Script //-->
    
    </td>
    
    <td align="right" >&nbsp;</td>
    
    <td>&nbsp;</td>
    
    </tr>
    
    <tr>
    <td align="right" class=txt>Tech Support Rep(s): <input name="techreptxt">
    
    <script>
    $('input').bind('blur', function() {
    
    $(this).val(function(i, val) {
    return val.toUpperCase();
    });
    
    });
    </script>
    
    </td>
    
    <td align="right" class=txt>Phone: <input type=text name=techphone></td>
    
    
    <td class=txt>Add Rep <input type="checkbox" rel="addrep" name="addrep" id="addrep" /></td>
    
    <!-- ******* Display additional Tech field //-->
    
    <tr rel="addrep">
    
    <td class=txt align=right align=right><label for="addrep">
    <span class="accessibility"></span> <font color=red>TS Backup/font></label>
    <input name="addrep" id="addrep" /></td>
    
    
    <td align=right class=txt><font color=red>Phone/font> <input type=text name="bkrepphone"></td>
    </tr>
    
    <!-- ****** End additional Tech field //-->
    </tr>
    <tr>
    <td align="right" class=txt>DBA: <input name="dbatxt">
    
    <script>
    
    $('input').bind('blur', function() {
    
    $(this).val(function(i, val) {
    return val.toUpperCase();
    });
    
    });
    </script>
    
    </td>
    
    <td align="right" class=txt>Phone: <input type=text name=dbaphone></td>
    
    <td class=txt>&nbsp; </td>
    
    </tr>
    
    <tr>
    
    <td align="right" class=txt>SQE: <input name="sqetxt">
    
    <script>
    $('input').bind('blur', function() {
    
    $(this).val(function(i, val) {
    return val.toUpperCase();
    });
    
    });
    </script>
    
    </td>
    
    <td align="right" class=txt>Phone: <input type=text name=sqephone></td>
    
    <td class=txt>&nbsp;</td>
    
    </tr>
    
    <tr>
    
    <td align="right" >&nbsp;</td>
    
    <td align="right" >&nbsp;</td>
    
    <td>&nbsp;</td>
    </tr>
    
    <tr>
    <td align="right">&nbsp;</td>
    
    <td align="right" colspan="2">&nbsp;</td>
    </tr>
    
    <tr>
    <td align="center" colspan=3><font face="Arial Narrow" size="4"><strong>Site Contacts</strong></font></td>
    
    </tr>
    <tr>
    <td align="right"class=txt>Site Contacts: <input name="sitecontactstxt">
    
    <script>
    $('input').bind('blur', function() {
    
    $(this).val(function(i, val) {
    return val.toUpperCase();
    });
    
    });
    </script>
    
    </td>
    <td align="right" class=txt>Phone: <input type=text name=sitecontactphone></td>
    
    </tr>
    <tr>
    <td align="right">&nbsp;</td>
    
    </tr>
    
    <tr>
    <td align="right" class=txt>Alineo Version: <input name="softwareinfotxt">
    
    <script>
    $('input').bind('blur', function() {
    
    $(this).val(function(i, val) {
    return val.toUpperCase();
    });
    
    });
    </script>
    </td>
    
    <td align="right" colspan="2">&nbsp;</td>
    
    </tr>
    <tr>
    
    <td align="right"></td>
    
    <td align="right" colspan="2"><input type="submit" value="Create Client Doc"></td>
    </tr>
    </form>
    </table>
    </body>
    </html>

    *****Here is the code for my ASP page:



    Code:
    <%
    
    OPTION EXPLICIT
    
    ' Waits until all the asp is done before dumping the text to the browser
    response.buffer = true
    
    
    'Receiving values from Form, assign the values entered to variables
    'Set a new variable for each new field added
    
    DIM newclient
    newclient=Request.Form("newclienttxt") 'Define Variable For New Client Acronym
    
    DIM tech
    tech=Request.Form("techreptxt") 'Define Variable For Tech Support Field
    
    DIM techph
    techph=Request.Form("techphone") 'Define Variable For Tech Support Phone
    
    DIM tsbk
    tsbk=Request.Form("addrep") 'Define Variable For Additional Tech Rep
    
    DIM bkrepph
    bkrepph=Request.Form=("bkrepphone") 'Define Variable For Additional Tech Phone
    
    DIM sqeph
    sqeph=Request.Form("sqephone") 'Define Variable For SQE Phone
    
    DIM dba
    dba=Request.Form("dbatxt") 'Define Variable For DBA
    
    DIM dbaph
    dbaph=Request.Form("dbaphone") 'Define Variable For DBA Phone
    
    DIM sitecontact
    sitecontact=Request.Form("sitecontactstxt") 'Define Variable For Site Contact
    
    DIM sitecontactph
    sitecontactph=Request.Form("sitecontactphone")'Define Variable For Site Contact Phone
    
    DIM softwareinfo
    softwareinfo=Request.Form("softwareinfotxt") 'Define Variable For Software
    
    ' Tells the browser to open word
    Response.ContentType = "application/vnd.ms-word"
    ' Adds a header to give the document a name
    response.AddHeader "content-disposition", "inline;filename=client.doc"
    %>
    
    <html>
    <head>
    <title></title>
    <meta content="Evrsoft First Page" name="GENERATOR">
    <style type="text/css">
    .title {
    FONT-SIZE: 15pt; COLOR: blue; FONT-FAMILY: arial; BACKGROUND-COLOR: #dddddd
    }
    .txt {
    FONT-SIZE: 25pt; COLOR: black; FONT-FAMILY: tahoma
    }
    TD.maintxt {
    FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: arial narrow
    }
    TD.subhead {
    FONT-SIZE: 15pt; COLOR: black; FONT-FAMILY: arial narrow
    }
    </style>
    </head>
    
    <body>
    <table width="550" align="center" border="1">
    <tbody>
    <tr>
    <td class="title" align="middle" colspan="2" span=""><%response.Write(newclient)%> Client Document</td>
    </tr>
    
    <tr>
    <td class="subhead" width="246">MEDecision Contact Information</td>
    
    <td width="290"></td>
    </tr>
    
    <tr>
    <td class="maintxt" width="248">Tech Support Rep: <%response.Write(tech)%></td>
    
    <td class="maintxt" width="290">Phone: <%response.write(techph)%></td>
    </tr>
    
    <tr>
    <td class="maintxt">TS Backup%Response.Write(tsbk)%></td>
    <td class="maintxt">Phone: <%Response.Write(bkrepph)%> </td>
    
    <tr>
    <td class="maintxt">Database Admin: <%Response.Write(dba)%></td>
    <td class="maintxt">Phone%response.write(dbaph)%></td>
    
    <tr>
    <td class="maintxt>Phone:
    </tr>
    
    <tr>
    <td class="maintxt" width="248">Site Contact: <%Response.Write(sitecontact)%></td>
    
    <td class="maintxt" width="290">Phone%Response.Write(sitecontactph)%></td>
    </tr>
    
    <tr>
    <td class="maintxt" width="248"></td>
    
    <td width="290"></td>
    </tr>
    
    <tr>
    <td class="maintxt" width="248"></td>
    
    <td width="290"></td>
    </tr>
    
    </table>
    
    
    <%
    <!-- This code is for testing which variables are being passed from the form. Take out when in PRODUCTION //-->
    
    ' Check to see if any querystring varibles exist
    if len (request.servervariables("query_string")) >1 then %>
    <b>Variables passed via QueryString</b><br>
    <!-- The following was passed via a form with a method equal to get, a hyperlink, or
    a form action with written varibles -->
    
    <%
    
    Dim variable_name
    Dim variable_value
    
    'Loop to find each querystring variable name and varible value
    
    for each variable_name in request.querystring
    variable_value=request.querystring(variable_name)
    
    'If there is a querystring variable name and value inputted then write it also
    response.write variable_name &" = "
    response.write variable_value &"<br>" &chr(13)
    next
    
    ' end for next loop for all querystrings
    end if
    
    ' end check for querstring values
    
    ' Check to see if any form varibles exist
    if len(request.form) > 0 then %>
    
    <p>
    
    <b>Variables passed via Post</b><br>
    
    <!-- The following was passed via a form with a method equal to post -->
    
    <%
    'Loop to find each variable name and varible value
    for each variable_name in request.form
    variable_value=request.form(variable_name)
    
    'If there is a variable name and value inputted then write it also
    response.write variable_name &" = "
    response.write variable_value &" <br>" &chr(13)
    next ' end for next loop for all
    end if ' end check for form values
    %>
    Last edited by Mittineague; May 26, 2011 at 16:15. Reason: reformatting bbcode tags


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •