Avatar billede japlex Nybegynder
03. juni 2001 - 11:45 Der er 6 kommentarer og
1 løsning

Tømning af input textfelter efter submit

når jeg trykker submit på min form smides textfelternes indhold fint ind i min database (access), felterne tømmes og  siden opdateres med den nye post, MEN hvis jeg trykker opdater igen sendes samme data i databasen igen uden at jeg har skrevet noget???

Hvad sker der ??

Har du brug for koden for at kunne svare - den er lidt lang - lavet i Dreamweaver
Avatar billede netsrac Praktikant
03. juni 2001 - 11:48 #1
Du skal efter at du har indsat i databasen, redirecte til samme side igen, så undgår du problemer, det gøres med

response.redirect(\"side.asp\")

Smid hele koden hvis du ikke kan få det til at virke.
Avatar billede japlex Nybegynder
03. juni 2001 - 11:49 #2
hvor i koden skal den placeres?
Avatar billede netsrac Praktikant
03. juni 2001 - 11:51 #3
Lige efter du indsætter i databasen, bare smid koden så skal jeg flette det ind.
Avatar billede japlex Nybegynder
03. juni 2001 - 11:52 #4
<%@LANGUAGE=\"VBSCRIPT\"%>
<!--#include file=\"Connections/regnskab.asp\" -->
<%
\' *** Edit Operations: declare variables

MM_editAction = CStr(Request(\"URL\"))
If (Request.QueryString <> \"\") Then
  MM_editAction = MM_editAction & \"?\" & Request.QueryString
End If

\' boolean to abort record edit
MM_abortEdit = false

\' query string to execute
MM_editQuery = \"\"
%>
<%
\' *** Insert Record: set variables

If (CStr(Request(\"MM_insert\")) <> \"\") Then

  MM_editConnection = MM_regnskab_STRING
  MM_editTable = \"Postering\"
  MM_editRedirectUrl = \"default.asp\"
  MM_fieldsStr  = \"txtDato|value|txtBeloeb|value|txtArt|value|txtBeskrivelse|value\"
  MM_columnsStr = \"Dato|\',none,\'\'|Beloeb|none,none,NULL|Art|\',none,\'\'|Beskrivelse|\',none,\'\'\"

  \' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, \"|\")
  MM_columns = Split(MM_columnsStr, \"|\")
 
  \' set the form values
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
  Next

  \' append the query string to the redirect URL
  If (MM_editRedirectUrl <> \"\" And Request.QueryString <> \"\") Then
    If (InStr(1, MM_editRedirectUrl, \"?\", vbTextCompare) = 0 And Request.QueryString <> \"\") Then
      MM_editRedirectUrl = MM_editRedirectUrl & \"?\" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & \"&\" & Request.QueryString
    End If
  End If

End If
%>
<%
\' *** Insert Record: construct a sql insert statement and execute it

If (CStr(Request(\"MM_insert\")) <> \"\") Then

  \' create the sql insert statement
  MM_tableValues = \"\"
  MM_dbValues = \"\"
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    FormVal = MM_fields(i+1)
    MM_typeArray = Split(MM_columns(i+1),\",\")
    Delim = MM_typeArray(0)
    If (Delim = \"none\") Then Delim = \"\"
    AltVal = MM_typeArray(1)
    If (AltVal = \"none\") Then AltVal = \"\"
    EmptyVal = MM_typeArray(2)
    If (EmptyVal = \"none\") Then EmptyVal = \"\"
    If (FormVal = \"\") Then
      FormVal = EmptyVal
    Else
      If (AltVal <> \"\") Then
        FormVal = AltVal
      ElseIf (Delim = \"\'\") Then  \' escape quotes
        FormVal = \"\'\" & Replace(FormVal,\"\'\",\"\'\'\") & \"\'\"
      Else
        FormVal = Delim + FormVal + Delim
      End If
    End If
    If (i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & \",\"
      MM_dbValues = MM_dbValues & \",\"
    End if
    MM_tableValues = MM_tableValues & MM_columns(i)
    MM_dbValues = MM_dbValues & FormVal
  Next
  MM_editQuery = \"insert into \" & MM_editTable & \" (\" & MM_tableValues & \") values (\" & MM_dbValues & \")\"

  If (Not MM_abortEdit) Then
    \' execute the insert
    Set MM_editCmd = Server.CreateObject(\"ADODB.Command\")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> \"\") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>
<%
set rcsPostering = Server.CreateObject(\"ADODB.Recordset\")
rcsPostering.ActiveConnection = MM_regnskab_STRING
rcsPostering.Source = \"SELECT Dato, Beloeb, Art, Beskrivelse FROM Postering ORDER BY Dato ASC\"
rcsPostering.CursorType = 0
rcsPostering.CursorLocation = 2
rcsPostering.LockType = 3
rcsPostering.Open()
rcsPostering_numRows = 0
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = 25
Dim Repeat1__index
Repeat1__index = 0
rcsPostering_numRows = rcsPostering_numRows + Repeat1__numRows
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
<script language=\"JavaScript\">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName==\"Netscape\")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->
</script>
<link rel=\"stylesheet\" href=\"std_stylesheet.css\" type=\"text/css\">
</head>
<body bgcolor=\"#FFFFFF\" text=\"#000000\">
<div id=\"Ny_Post\" style=\"position:absolute; width:693px; height:75px; z-index:1; left: 18px; top: 19px\">
  <form name=\"postering\" method=\"POST\" action=\"<%=MM_editAction%>\">
    <table width=\"81%\" border=\"0\">
      <tr>
        <td width=\"72\"><b>Dato:</b></td>
        <td width=\"55\"><b>Bel&oslash;b:</b></td>
        <td width=\"79\"><b>Art:</b></td>
        <td width=\"476\"><b>Beskrivelse:</b></td>
      </tr>
      <tr>
        <td align=\"center\" width=\"72\">
          <input type=\"text\" name=\"txtDato\" size=\"8\" class=\"form\">
        </td>
        <td align=\"center\" width=\"55\">
          <input type=\"text\" name=\"txtBeloeb\" size=\"6\" class=\"form\">
        </td>
        <td align=\"center\" width=\"79\">
          <input type=\"text\" name=\"txtArt\" class=\"form\" size=\"12\">
        </td>
        <td align=\"center\" width=\"476\">
          <input type=\"text\" name=\"txtBeskrivelse\" class=\"form\" size=\"50\" align=\"default\">
        </td>
      </tr>
      <%
While ((Repeat1__numRows <> 0) AND (NOT rcsPostering.EOF))
%>
      <tr>
        <td align=\"center\" width=\"72\"><%=(rcsPostering.Fields.Item(\"Dato\").Value)%> </td>
        <td align=\"center\" width=\"55\"><%=(rcsPostering.Fields.Item(\"Beloeb\").Value)%> </td>
        <td align=\"center\" width=\"79\"><%=(rcsPostering.Fields.Item(\"Art\").Value)%> </td>
        <td align=\"center\" width=\"476\"><%=(rcsPostering.Fields.Item(\"Beskrivelse\").Value)%> </td>
      </tr>
      <%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  rcsPostering.MoveNext()
Wend
%>
    </table>
    <p>
      <input type=\"hidden\" name=\"MM_insert\" value=\"true\">
    </p>
    <p>
      <input type=\"submit\" name=\"Indsaet\" value=\"Inds&aelig;t\" class=\"form\">
    </p>
  </form>
</div>
</body>
</html>
<%
rcsPostering.Close()
%>
Avatar billede japlex Nybegynder
03. juni 2001 - 11:55 #5
Jeg har fået det til at virke - men send da gerne dit svar alligevel - du får under alle omstændighederne pointene.

Tak :-)
Avatar billede netsrac Praktikant
03. juni 2001 - 11:55 #6
Damn noget slam kode Dreamweaver laver, nå men sådan her:

<%@LANGUAGE=\"VBSCRIPT\"%>
<!--#include file=\"Connections/regnskab.asp\" -->
<%
\' *** Edit Operations: declare variables

MM_editAction = CStr(Request(\"URL\"))
If (Request.QueryString <> \"\") Then
  MM_editAction = MM_editAction & \"?\" & Request.QueryString
End If

\' boolean to abort record edit
MM_abortEdit = false

\' query string to execute
MM_editQuery = \"\"
%>
<%
\' *** Insert Record: set variables

If (CStr(Request(\"MM_insert\")) <> \"\") Then

  MM_editConnection = MM_regnskab_STRING
  MM_editTable = \"Postering\"
  MM_editRedirectUrl = \"default.asp\"
  MM_fieldsStr  = \"txtDato|value|txtBeloeb|value|txtArt|value|txtBeskrivelse|value\"
  MM_columnsStr = \"Dato|\',none,\'\'|Beloeb|none,none,NULL|Art|\',none,\'\'|Beskrivelse|\',none,\'\'\"

  \' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, \"|\")
  MM_columns = Split(MM_columnsStr, \"|\")
 
  \' set the form values
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
  Next

  \' append the query string to the redirect URL
  If (MM_editRedirectUrl <> \"\" And Request.QueryString <> \"\") Then
    If (InStr(1, MM_editRedirectUrl, \"?\", vbTextCompare) = 0 And Request.QueryString <> \"\") Then
      MM_editRedirectUrl = MM_editRedirectUrl & \"?\" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & \"&\" & Request.QueryString
    End If
  End If

End If
%>
<%
\' *** Insert Record: construct a sql insert statement and execute it

If (CStr(Request(\"MM_insert\")) <> \"\") Then

  \' create the sql insert statement
  MM_tableValues = \"\"
  MM_dbValues = \"\"
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    FormVal = MM_fields(i+1)
    MM_typeArray = Split(MM_columns(i+1),\",\")
    Delim = MM_typeArray(0)
    If (Delim = \"none\") Then Delim = \"\"
    AltVal = MM_typeArray(1)
    If (AltVal = \"none\") Then AltVal = \"\"
    EmptyVal = MM_typeArray(2)
    If (EmptyVal = \"none\") Then EmptyVal = \"\"
    If (FormVal = \"\") Then
      FormVal = EmptyVal
    Else
      If (AltVal <> \"\") Then
        FormVal = AltVal
      ElseIf (Delim = \"\'\") Then  \' escape quotes
        FormVal = \"\'\" & Replace(FormVal,\"\'\",\"\'\'\") & \"\'\"
      Else
        FormVal = Delim + FormVal + Delim
      End If
    End If
    If (i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & \",\"
      MM_dbValues = MM_dbValues & \",\"
    End if
    MM_tableValues = MM_tableValues & MM_columns(i)
    MM_dbValues = MM_dbValues & FormVal
  Next
  MM_editQuery = \"insert into \" & MM_editTable & \" (\" & MM_tableValues & \") values (\" & MM_dbValues & \")\"

  If (Not MM_abortEdit) Then
    \' execute the insert
    Set MM_editCmd = Server.CreateObject(\"ADODB.Command\")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> \"\") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If
\'*******************HER**********************
response.redirect(\"side.asp\")
End If
%>
<%
set rcsPostering = Server.CreateObject(\"ADODB.Recordset\")
rcsPostering.ActiveConnection = MM_regnskab_STRING
rcsPostering.Source = \"SELECT Dato, Beloeb, Art, Beskrivelse FROM Postering ORDER BY Dato ASC\"
rcsPostering.CursorType = 0
rcsPostering.CursorLocation = 2
rcsPostering.LockType = 3
rcsPostering.Open()
rcsPostering_numRows = 0
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = 25
Dim Repeat1__index
Repeat1__index = 0
rcsPostering_numRows = rcsPostering_numRows + Repeat1__numRows
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
<script language=\"JavaScript\">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName==\"Netscape\")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->
</script>
<link rel=\"stylesheet\" href=\"std_stylesheet.css\" type=\"text/css\">
</head>
<body bgcolor=\"#FFFFFF\" text=\"#000000\">
<div id=\"Ny_Post\" style=\"position:absolute; width:693px; height:75px; z-index:1; left: 18px; top: 19px\">
  <form name=\"postering\" method=\"POST\" action=\"<%=MM_editAction%>\">
    <table width=\"81%\" border=\"0\">
      <tr>
        <td width=\"72\"><b>Dato:</b></td>
        <td width=\"55\"><b>Bel&oslash;b:</b></td>
        <td width=\"79\"><b>Art:</b></td>
        <td width=\"476\"><b>Beskrivelse:</b></td>
      </tr>
      <tr>
        <td align=\"center\" width=\"72\">
          <input type=\"text\" name=\"txtDato\" size=\"8\" class=\"form\">
        </td>
        <td align=\"center\" width=\"55\">
          <input type=\"text\" name=\"txtBeloeb\" size=\"6\" class=\"form\">
        </td>
        <td align=\"center\" width=\"79\">
          <input type=\"text\" name=\"txtArt\" class=\"form\" size=\"12\">
        </td>
        <td align=\"center\" width=\"476\">
          <input type=\"text\" name=\"txtBeskrivelse\" class=\"form\" size=\"50\" align=\"default\">
        </td>
      </tr>
      <%
While ((Repeat1__numRows <> 0) AND (NOT rcsPostering.EOF))
%>
      <tr>
        <td align=\"center\" width=\"72\"><%=(rcsPostering.Fields.Item(\"Dato\").Value)%> </td>
        <td align=\"center\" width=\"55\"><%=(rcsPostering.Fields.Item(\"Beloeb\").Value)%> </td>
        <td align=\"center\" width=\"79\"><%=(rcsPostering.Fields.Item(\"Art\").Value)%> </td>
        <td align=\"center\" width=\"476\"><%=(rcsPostering.Fields.Item(\"Beskrivelse\").Value)%> </td>
      </tr>
      <%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  rcsPostering.MoveNext()
Wend
%>
    </table>
    <p>
      <input type=\"hidden\" name=\"MM_insert\" value=\"true\">
    </p>
    <p>
      <input type=\"submit\" name=\"Indsaet\" value=\"Inds&aelig;t\" class=\"form\">
    </p>
  </form>
</div>
</body>
</html>
<%
rcsPostering.Close()
%>



side.asp skal self. udskiftes med dit filnavn.
Avatar billede japlex Nybegynder
03. juni 2001 - 11:58 #7
Ja - dreamweaver laver virkelig \"spaghetti\" , men det er ok for mig lige nu - er ny indenfor ASP

Tak for svaret
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester