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
LVL 1
thatelvisAsked:
Who is Participating?
 
matthijn01Connect With a Mentor Commented:
Well, i thought with that code, if the submit takes more than 2 sec, force a refresh.

But anyway, you can do this.

When the form is submitted, put this in your html. (Only show when the form is submitted)

Where '2' is the number in seconds after which to refresh, and http://www.theurl.com is your current url.
<meta http-equiv="refresh" content="2;URL=http://www.theurl.com/" />

Open in new window

0
 
matthijn01Commented:
Hello, why would you want to have the page be refreshed within 2 seconds? Because it could be possible that the form is not ready with the submit.

But anyway, here is a code that would submit the page, and refresh the page after two seconds.
<script type="text/javsascript">
	function forceRefresh() {
		setTimeout("document.location.href = document.location.href;", "2000");
	}
</script>
<form method="post" onsubmit="forceRefresh()">
<!-- Your form here -->
<input type="submit" value="Send" />
</form>

Open in new window

0
 
matthijn01Commented:
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>

Open in new window

0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
thatelvisAuthor Commented:
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
0
 
matthijn01Commented:
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.
0
 
thatelvisAuthor Commented:
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
0
 
thatelvisAuthor Commented:
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
<%
 
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
 
%>

Open in new window

0
 
thatelvisAuthor Commented:
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('document.location.href=document.location.href',5000)" >
  </label>
</form>

thanks for your help

k
0
 
thatelvisAuthor Commented:
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.

0
 
matthijn01Commented:
You must show that when the form is submitted.

In php is would be like this
if(isset($_POST['download'])) {
echo '<meta http-equiv="refresh" content="2;URL=http://www.theurl.com/" />';
}

Open in new window

0
 
matthijn01Commented:
Where is the edit button on this page.. I see that you removed the url part, something what sould be there.
0
 
thatelvisAuthor Commented:
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
0
 
thatelvisAuthor Commented:
cheers sorry for the delay,
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.