thatelvis
asked on
submit and onclick refresh page
Hello,
I have a form with a submit button, when the form is submitted how can I have the page refreshed within 2 seconds after the form was submitted.
regards
k
I have a form with a submit button, when the form is submitted how can I have the page refreshed within 2 seconds after the form was submitted.
regards
k
I forgot a 'return true;' in the code above, so here it is with return true
<script type="text/javsascript">
function forceRefresh() {
setTimeout("document.location.href = document.location.href;", "2000");
return true;
}
</script>
<form method="post" onsubmit="forceRefresh()">
<!-- Your form here -->
<input type="submit" value="Send" />
</form>
ASKER
hi yea some how this wont work for me , I am using what you gave in my form which I cannot give you access to at the moment. I have a submit button when clicked will allow one to download a file, every time the file is downloaded I show a number on my page as to how many other times one can download the file.
any way the download works fab, but the page does not refresh.
k
any way the download works fab, but the page does not refresh.
k
So what you really want is an counter which updates every time a user clicks on the download button?
You should not do that with refreshing, but when the form is submitted, increase the value of the times the file is downloaded before you display that number on the page, that way you always have the newest value.
You should not do that with refreshing, but when the form is submitted, increase the value of the times the file is downloaded before you display that number on the page, that way you always have the newest value.
ASKER
I was grabing the value from the db as the db column increases every time the file is downloaded. i was expecting to refresh the page to show the new value from my database.
k thanks
k thanks
ASKER
Below is the asp code I use for the download, it is part of a webassist extension. they always seem to release have baked goods.
k
k
<%
Dim WA_DFP_DownloadStatus
Set WA_DFP_DownloadStatus = Server.CreateObject("Scripting.Dictionary")
Sub WA_DFP_SetupDownloadStatusStruct (statusName)
Set WA_DFP_DownloadStatus.Item(statusName) = New WA_DFP_DownloadStatusItem
End Sub
' Download status codes and error messages:
' -1 : Trigger did not run : ""
' 0 : File not found : "File not found"
' 1 : Download processed : ""
Sub WA_DFP_DownloadFile (statusName, folderPath, fileName, newFileName, updateDB, connectionName, tableName, keyColumn, recordID, countColumn)
Response.Buffer = True
Response.Clear
Set WA_DFP_DownloadStatus.Item(statusName) = New WA_DFP_DownloadStatusItem
Dim fso
Set fso = Server.CreateObject("Scripting.FileSystemObject")
If folderPath = "" Then
folderPath = "./"
End If
Dim filePath
filePath = Replace(Server.MapPath(folderPath) & "\" & fileName, "/", "\")
Dim defaultFileName
defaultFileName = "[FileName]"
Dim ext
ext = fso.GetExtensionName(fileName)
Dim basename
basename = fso.GetBaseName(fileName)
If newFileName <> defaultFileName Then
If ext <> "" AND InStr(newFileName, ".") = 0 Then
newFileName = newFileName & "." & ext
End If
newFileName = Replace(newFileName, defaultFileName, basename)
Else
newFileName = fileName
End If
WA_DFP_DownloadStatus.Item(statusName).fileName = basename
WA_DFP_DownloadStatus.Item(statusName).fileFullName = fso.GetFileName(fileName)
WA_DFP_DownloadStatus.Item(statusName).fileExtension = ext
WA_DFP_DownloadStatus.Item(statusName).serverDirectory = fso.GetParentFolderName(filePath)&"\"
WA_DFP_DownloadStatus.Item(statusName).serverFilePath = filePath
If fso.FileExists(filePath) Then
Dim fileObj
Set fileObj = fso.GetFile(filePath)
WA_DFP_DownloadStatus.Item(statusName).statusCode = 1
If updateDB Then
Dim cmd
Set cmd = Server.CreateObject ("ADODB.Command")
cmd.ActiveConnection = connectionName
cmd.CommandText = "Update " & tableName & " SET " & countColumn & "=" & countColumn & "+1 WHERE " & keyColumn & " = " & recordID & ""
cmd.CommandType = 1 ' adCmdText
cmd.CommandTimeout = 0
cmd.Execute()
End If
Set streamObj = Server.CreateObject("ADODB.Stream")
streamObj.Open
streamObj.Type = 1 ' adTypeBinary
streamObj.LoadFromFile filePath
Response.AddHeader "Content-Disposition", "attachment; filename= " & fso.GetFileName(newFileName)
Response.AddHeader "Content-Length", fileObj.Size
Response.Charset = "UTF-8"
Response.ContentType = "application/octet-stream"
Do While Not streamObj.EOS
Response.BinaryWrite streamObj.Read(1048576) '1048576 = 1 MB (the IIS limit is 4 MB)
Response.Flush()
Loop
streamObj.Close
Set streamObj = Nothing
Response.End()
Else
WA_DFP_DownloadStatus.Item(statusName).statusCode = 0
WA_DFP_DownloadStatus.Item(statusName).errorMessage = "File: '" & filePath & "' not found"
End If
End Sub
Class WA_DFP_DownloadStatusItem
Public statusCode
Public errorMessage
Public fileName
Public fileFullName
Public fileExtension
Public serverDirectory
Public serverFilePath
private sub Class_Initialize()
statusCode = -1
errorMessage = ""
fileName = ""
fileFullName = ""
fileExtension = ""
serverDirectory = ""
serverFilePath = ""
end sub
End Class
Function WA_FileAssist_RenameFile(folderPath, fileName, newFileName)
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
If folderPath = "" Then
folderPath = "./"
End If
Dim filepath : filePath = Server.MapPath(folderPath) & "\" & fileName
Dim newFileNameDefault : newFileNameDefault = "[FileName]"
Dim newFilePath
If (fso.GetBaseName(newFileName) = newFileName ) Then
If fso.GetExtensionName(fileName) <> "" Then
newFileName = newFileName & "." & fso.GetExtensionName(fileName)
End If
End If
newFileName = Replace(newFileName, newFileNameDefault, fso.GetBaseName(fileName))
newFilePath = Server.MapPath(folderPath) & "\" & newFileName
WA_FileAssist_RenameFile = False
If(fso.FileExists(filePath)) Then
fso.MoveFile filePath, newFilePath
WA_FileAssist_RenameFile = True
End If
End Function
Function WA_FileAssist_DeleteFile (folderPath, fileName)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If folderPath = "" Then
folderPath = "./"
End If
filePath = Server.MapPath(folderPath) & "\" & fileName
WA_FileAssist_DeleteFile = False
If(fso.FileExists(filePath)) Then
Dim file
Set file = fso.GetFile(filePath)
If(file.Attributes MOD 2 = 0) Then
fso.DeleteFile(filePath)
WA_FileAssist_DeleteFile = True
End If
End If
End Function
%>
ASKER
how would I get this to work, the form gets sumbitted to its own page. how can i get it to refresh on submit
<form name="form1" method="post" action="">
<label>
<input type="submit" name="button" id="button" value="Submit" onClick="setTimeout('docum ent.locati on.href=do cument.loc ation.href ',5000)" >
</label>
</form>
thanks for your help
k
<form name="form1" method="post" action="">
<label>
<input type="submit" name="button" id="button" value="Submit" onClick="setTimeout('docum
</label>
</form>
thanks for your help
k
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
I have used this
<%
If Session("refreshed") <> 1 Then
Session("refreshed") = 1
Response.Write("<meta http-equiv=""refresh"" content=""5""/>")
End If
%>
all in all i think the page doesnt refresh when the form is submitted. I am using a form and a webassist download extension. when clicked i download a large zip file but the page doesnt refresh when either completed or during the download thats the problem.
I have used this
<%
If Session("refreshed") <> 1 Then
Session("refreshed") = 1
Response.Write("<meta http-equiv=""refresh"" content=""5""/>")
End If
%>
all in all i think the page doesnt refresh when the form is submitted. I am using a form and a webassist download extension. when clicked i download a large zip file but the page doesnt refresh when either completed or during the download thats the problem.
You must show that when the form is submitted.
In php is would be like this
In php is would be like this
if(isset($_POST['download'])) {
echo '<meta http-equiv="refresh" content="2;URL=http://www.theurl.com/" />';
}
Where is the edit button on this page.. I see that you removed the url part, something what sould be there.
ASKER
thank you the page name is called a.asp the action is a.asp. I belive the problem is with the webassist extension code.
as i cannot seem to call a hidden field value to the page on form submit
k
as i cannot seem to call a hidden field value to the page on form submit
k
ASKER
cheers sorry for the delay,
But anyway, here is a code that would submit the page, and refresh the page after two seconds.
Open in new window