473,322 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

JavaScript for time delay onClick goto URL for Form submission

1
I am working in Dreamweaver 8, and I have created a simple form: http://www.realmofmystery.com/app.html

This is a free website I am doing for some friends, so nothing fancy. And, I learned web design before all the CGI and PHP stuff got big, so I prefer to do things simply.

The form worked fine, emails the results like perfect, but it refused to redirect the page to the confirmation. I thought I could add an onClick to the submit button, but this cancels out the form processing.

So, I called my hosting people, they told me to redirect the form action from a mailto, to the gdform.asp file on the server. I did this, and I keep getting errors now. It refuses to work. They are no help, they say I made a mistake scripting, only I didn't script anything!!! I am just using their script. So, I think this could be solved with a simple piece of JavaScript, problem is, I don't know enough about JavaScript to write my own script, but I am assuming the onClick would work if there was also a time delay written into the script that gave the form enough time to submit before redirecting to the confirmation page.

Does anyone have a script to delay the onClick event so I can bypass this?

If you need any extra info, let me know. Also, here is the code contained in my gdform.asp:

Expand|Select|Wrap|Line Numbers
  1. <%
  2.  
  3. Dim landing_page, host_url
  4. Dim fso, outfile, filename, dirname, myFolder
  5. Dim req_method, key, value
  6. Dim bErr, errStr, bEmpty
  7. On Error resume next
  8. bErr = false
  9. bEmpty = true
  10. errStr = ""
  11. Set fso = Server.CreateObject("Scripting.FileSystemObject")
  12. host_url = Request.ServerVariables("HTTP_HOST")
  13. req_method = Request.ServerVariables("REQUEST_METHOD")
  14. dtNow = Now()
  15. filename = Server.MapPath("\ssfm")
  16. dirname = filename
  17. filename = filename & "\gdform_" & DatePart("M", dtNow) & DatePart("D", dtNow) & DatePart("YYYY", dtNow) & DatePart("N", dtNow) & DatePart("S", dtNow)
  18.  
  19. Function FormatVariableLine(byval var_name, byVal var_value)
  20.     Dim tmpStr
  21.     tmpStr = tmpStr & "<GDFORM_VARIABLE NAME=" & var_name & " START>" & vbCRLF
  22.     tmpStr = tmpStr & var_value & vbCRLF
  23.     tmpStr = tmpStr & "<GDFORM_VARIABLE NAME=" & var_name & " END>"
  24.     FormatVariableLine = tmpStr
  25. end function
  26.  
  27. Sub OutputLine(byVal line)
  28.    outfile.WriteLine(line)
  29. end sub
  30.  
  31. if err.number = 0 then
  32.     Set outfile = fso.CreateTextFile(filename, true, false)
  33.     if err.number <> 0 then
  34.             bErr = true
  35.             errStr = "Error creating file! Directory may not be writable or may not exist.<br>Unable to process request."
  36.     else
  37.         if(req_method = "GET") then
  38.             for each Item in request.QueryString
  39.                 if item <> "" then
  40.                     bEmpty = false
  41.                     key = item
  42.                     value = Request.QueryString(item)
  43.                     if(lcase(key) = "redirect") then
  44.                         landing_page = value
  45.                     else
  46.                         line = FormatVariableLine(key, value)
  47.                         Call OutputLine(line)
  48.                     end if
  49.                 end if    
  50.             next
  51.         elseif (req_method = "POST") then
  52.             for each Item in request.form
  53.                 if item <> "" then
  54.                     bEmpty = false
  55.                     key = item
  56.                     value = Request.form(item)
  57.                     if(lcase(key) = "redirect") then
  58.                         landing_page = value
  59.                     else
  60.                         line = FormatVariableLine(key, value)
  61.                         Call OutputLine(line)
  62.                     end if
  63.                 end if    
  64.             next
  65.         end if
  66.         outfile.close
  67.     end if    
  68.     if(bEmpty = true) AND errStr = "" then
  69.         bErr = true
  70.         errStr = errStr & "<br>No variables sent to form! Unable to process request."
  71.     end if
  72.     if(bErr = false) then    
  73.         if (landing_page <> "") then
  74.             response.Redirect "http://" & host_url & "/" & landing_page
  75.         else
  76.             response.Redirect "http://" & host_url    
  77.         end if
  78.     else
  79.         Response.Write errStr
  80.     end if    
  81.     set fso = nothing
  82. else
  83.   Response.Write " An Error Occurred creating mail message. Unable to process form request at this time."
  84. end if
  85. %>
  86.  
When I first changed the form to direct here, I got the first error it mentions, then when I removed the JavaScript to validate the form on submission, I started getting the second error.

Thanks in advance!
Mar 30 '08 #1
2 5049
acoder
16,027 Expert Mod 8TB
This seems like an ASP problem rather than a JavaScript one. I'll move this to the ASP forum.

Have you made sure the form field names match those required by the script?
Apr 1 '08 #2
pronerd
392 Expert 256MB
I am assuming the onClick would work if there was also a time delay written into the script that gave the form enough time to submit before redirecting to the confirmation page.
That would not be a good solution since the user would see the confirmation page, even if an error occurred and their submition did not go though. You really want your server side logic to process the request, then if the request was successfully processed forward them to the confirmation page. Otherwise you want to return an error so they know the request did not go though.

Also, as soon as you submit a request the current page stops executing, so it can not then submitted a second request later. So the only way for what you describe to work would be for the first request to be submitted via AJAX, and then submit the second request to the confirmation page.
Apr 1 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.