• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

Submitting form without Submit button

I have a table of information with one input field (surrounded by a form).
<tr>
 <td>New File:</td>
 <td>
    <form name="form1" method="POST">
    <input type="file" name="MyFile" value="<%=MyFile%>" onChange="form1.submit()">
    </form>
 </td>
 <td>Part ID:</td>
 <td><%=PartID%></td>
</tr>

Since I'm using INPUT TYPE=FILE, I get a BROWSE button.  I need to go out and select a file and then update two records using SQL without adding a second button, i.e. on the form.  When I click the BROWSE button, the form needs to SUBMIT, do the SQL update and refresh the page (reload the SQL that loaded the page to begin with).  My SQL to do the UPDATE is in the <HEAD> section and looks like:
if Trim(request.form("MyFile")) <> "" then
  sSQL = "UPDATE PartSupport SET pecADLevel=' " & ApFix(Trim(Request.form("MyFile"))) & "', " &_
      "pecADCompDate=#" & Date & "# WHERE PartSupport.PartSupportID=" & PartID

  oConn.Execute(sSQL)
      
  sSQL = "UPDATE PartSupport SET pedActive=3 " &_
      "WHERE PartSupport.PartSupportID=" & prevPart

  oConn.Execute(sSQL)
end if

When the Form is Submitted, it doesn't seem like I'm getting back up to the top of the program again (reloading the page).  Can you help?  (If you'd like the whole code, I can supply that, it's only 236 lines.)
Thanks.
0
bigtwig
Asked:
bigtwig
  • 3
  • 2
3 Solutions
 
hujiCommented:
You didn't provide what the ACTION of the form is set to. Supposing that the form is on Page1.asp, and it submites to Page2.asp, you need to add this to the end of the second page:

response.redirect "Page1.asp"

to make it redirect back to the first page again.

If you need more help, please post more parts of your code. You can also upload them on http://www.ee-stuff.com and let us know the link, to download it. It is useful if the code is very long.
0
 
bigtwigAuthor Commented:
Thanks huji for the reply.  The form submits to itself.
0
 
bugs021997Commented:
You can try something like this...

<FORM>
Select a destination:<P>
<SELECT MULTIPLE onChange="window.location=this.options[this.selectedIndex].value;" SIZE="3">
<OPTION VALUE="index.htm">Title Page
<OPTION VALUE="sound.htm">Sound Tags Page
<OPTION VALUE="forms.htm#TOC">Table of Contents
<OPTION VALUE="text.htm">Text Tags Page
</SELECT>
</FORM>
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
bugs021997Commented:
<script language="javascript">
function submitThis(){
document.form1.submit();
}
</script>

<tr>
 <td>New File:</td>
 <td>
    <form name="form1" method="POST" ACTION="fileName.asp?exe=Yes">
    <input type="file" name="MyFile" value="<%=MyFile%>" onChange="submitThis()">
    </form>
 </td>
 <td>Part ID:</td>
 <td><%=PartID%></td>
</tr>
<%
if Trim(request.querystring("exe")) <> "" then
  sSQL = "UPDATE PartSupport SET pecADLevel=' " & ApFix(Trim(Request.form("MyFile"))) & "', " &_
      "pecADCompDate=#" & Date & "# WHERE PartSupport.PartSupportID=" & PartID

  oConn.Execute(sSQL)
     
  sSQL = "UPDATE PartSupport SET pedActive=3 " &_
      "WHERE PartSupport.PartSupportID=" & prevPart

  oConn.Execute(sSQL)
end if
%>
0
 
bugs021997Commented:
Also an important thing, the fact that you are using FILE as the input your FORM tag should be changed to something as below

<form action="fileName.jsp" method="POST"  enctype="multipart/form-data">

<input type="file" name="file"><br>

<input type="submit">
</form>


Check this...http://www.asp101.com/articles/jacob/scriptupload.asp
0
 
bigtwigAuthor Commented:
I'm not really uploading the file, just writing the path to a table.
I put the <FORM> tag higher in the program and I'm getting what I expected, but now my problem is that I'm not pulling the right PartID and PrevPart to do my UPDATE SQL.  Since I'm looping through objRS, it's pulling the last PartID and PrevPart that it displays, not the one that I have expanded.  Here's the entire code, cleaned up a little.  Search for PartID, PrevPart and MyFile.... thanks!

<%@ Language=VBScript %>
<!--#include file="../includes/oconn.asp"-->
<!--#include file="../includes/ApFix.asp"-->

<HTML>
<HEAD>
<script type="text/javascript" src="../includes/switchcontent.js" ></script>
<script type="text/javascript" src="../includes/switchicon.js">
/***********************************************
* Switch Content script II (icon based)- © Dynamic Drive (www.dynamicdrive.com)
* Requires switchcontent.js and included before this file!
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
</script>
<%
if request.form("MyFile") <> "" then
  sSQL = "UPDATE PartSupport SET pecADLevel=' " & ApFix(Trim(Request.form("MyFile"))) & "', " &_
      "pedActive=2, pecADCompDate='" & Date & "' " &_
      "WHERE jobtrack..PartSupport.PartSupportID=" & Request.Form("PartID")
  oConn.Execute(sSQL)
      
  sSQL = "UPDATE PartSupport SET pedActive=3 WHERE PartSupport.PartSupportID=" & Request.Form("PrevPart")
  oConn.Execute(sSQL)                  
end if
%>

<style type="text/css">
.iconspan{
margin:1px;
font-size:12px;
font-weight: bold;
}
.eg-bar{
background-color: #EEF5D3;
border: 1px solid black;
padding: 1px;
font-size: 10px;
font-weight: bold;
}
div.eg-bar{
width: 90%;
}
.icongroup1{
width: 90%;
font-size: 12px;
}
</style>
</HEAD>

<BODY bgcolor=Beige>
<FORM name="ToDoList" method="POST">
<%
Dim Requested, JobNumber, EngFname, EngLname, Customer, ProgramName, PartNum, jtmID, PlotsComp, PlotsUncomp, PrintsComp, PrintsUncomp
Dim updTitleBlock, DataLog, Comments, Engineer, newPath, oldPath
Dim objRS, objRS2, objRS3
Set objRS=Server.CreateObject("ADODB.Recordset")

  sSQL="SELECT DISTINCT jtmJobTrackingMaster.jtmJobNo, jtmJobTrackingMaster.jtmEngineer, " &_
      "jtmJobTrackingMaster.jtmPartNo, jtmJobTrackingMaster.jtmCustomer,jtmJobTrackingMaster.jtmPROID, PartSupport.*" &_
      "FROM jobtrack.dbo.PartSupport " &_
      "LEFT OUTER JOIN jtmJobTrackingMaster ON PartSupport.pecADJobNum = jtmJobTrackingMaster.jtmJobNo " &_
      "WHERE PartSupport.pedActive = 1"

  objRS.Open sSQL, oConn                  
                  
  if objRS.eof then
       response.redirect("JobSelect.asp")
      objRS.Close
  end if

  objRS.movefirst
  Do while NOT objRS.eof
      NumOfFiles=NumOfFiles+1
      objRS.movenext
  loop
%>

<h2>Data Activation "To Do" List ( <%=NumOfFiles%> Files waiting for Activation)</h2>
<!--
Can add the ability to Expand/Contract all items. Jon wants it disabled, for now
<br><a href="javascript:faq.sweepToggle('contract')">Contract All</a> | <a href="javascript:faq.sweepToggle('expand')">Expand All</a>-->

<%      
objRS.movefirst
if not objRS.eof then
      Do while NOT objRS.eof
            Requested = objRS("pecADActDate")
            JobNumber = objRS("jtmJobNo")
            Customer = objRS("jtmCustomer")      
            ProgramName = objRS("jtmPROID")
            PartNum = objRS("jtmPartNo")
            PartID = objRS("PartSupportID")
            PlotsComp = objRS("pedPlotADComp")
            PlotsUncomp = objRS("pedPlotADUncomp")
            PrintsComp = objRS("pedPrintADComp")
            PrintsUncomp = objRS("pedPrintADUncomp")
            updTitleBlock = objRS("pedUpdateTitleBlock")
            DataLog = objRS("pedADDataLogInfo")
            Comments = objRS("pedComments")
            Engineer = objRS("jtmEngineer")
            newPath = objRS("pecADLevel")
            PrevPart = objRS("pedPrevPartID")
            'jtmID = objRS("jtmID")      
                  
Set objRS2=Server.CreateObject("ADODB.Recordset")

sSQL2 = "SELECT jtmJobTrackingMaster.jtmEngineer, empEmployeeMaster.empFirstName, empEmployeeMaster.empLastName " &_
            "FROM jtmJobTrackingMaster " &_
            "INNER JOIN empEmployeeMaster ON empEmployeeMaster.empID = jtmJobTrackingMaster.jtmEngineer " &_
            "WHERE jtmJobTrackingMaster.jtmEngineer=" & Engineer
                  
objRS2.Open sSQL2, oConn                  

      EngFname = objRS2("empFirstName")
      EngLname = objRS2("empLastName")
      
Set objRS3=Server.CreateObject("ADODB.Recordset")

sSQL3 = "SELECT pecADLevel FROM PartSupport WHERE PartSupport.PartSupportID=" & PrevPart
                  
objRS3.Open sSQL3, oConn

      if not objRS3.eof then
            oldPath = objRS3("pecADLevel")
      end if
%>                  

<div class="eg-bar">
<span id="faq<%=PartID%>-title" class="iconspan"><img src="file:///Z|/walker/images/minus.gif" /></span>
<table width="100%" class="iconspan">
 <tr>
  <td width="10%" align=center><%=Requested%></td>
  <td width="10%" align=center><%=JobNumber%></td>
  <td width="15%" align=left><%=EngFname%>&nbsp;<%=EngLname%></td>
  <td width="25%" align=left><%=Customer%></td>
  <td width="20%" align=center><%=ProgramName%></td>
  <td width="20%" align=left><%=PartNum%></td>
 </tr>
</TABLE>
</div>
<div id="faq<%=PartID%>" class="icongroup1">
<table bgcolor="white" width="100%" class="icongroup1">
<tr><td align=right width="10%">New Data:</td><td align=left colspan=3><a href='<%=newPath%>' target="_blank"><%=newPath%></a></td></tr>
<tr><td align=right>Replaces:</td><td align=left colspan=3><a href='<%=oldPath%>' target="_blank"><%=oldPath%></a></td></tr>
<%
 if updTitleBlock then
   response.Write("<tr><td colspan=4><b>Title block information requires updating.</b></td></tr>")
 end if
%>
<tr>
 <td align="right">New File:</td>
 <td>
      <input type="hidden" name="PartID" VALUE="<%=PartID%>">
      <input type="hidden" name="PrevPart" VALUE="<%=PrevPart%>">      
      <input type="file" name="MyFile" id="MyFile" onChange="form.submit()">
 </td>
 <td align="right">Part ID:</td>
 <td align="left"><%=PartID%></td>
</tr>
</table>
</div>

<%
      objRS.movenext
   loop
   end if
%>      
<table>
</table>

<script type="text/javascript">
var faq=new switchicon("icongroup1", "div") //Limit scanning of switch contents to just "div" elements
faq.setHeader('<img src="../images/minus.gif" />', '<img src="../images/plus.gif" />') //set icon HTML
faq.collapsePrevious(true) //Allow only 1 content open at any time
faq.setPersist(false) //No persistence enabled
faq.defaultExpanded(0) //Set 1st content to be expanded by default
faq.init()
</script>

</FORM>
<% objRS.close %>
</BODY>
</HTML>
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now