Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form memory

Status
Not open for further replies.

Hondy

Technical User
Mar 3, 2003
864
GB
Hi

Is it possible to have a form retain its settings after clicking submit?

I have a form that alters what data is retrived on the same page, there are 3 options and if the user clicks one, then clicks submit but then decides to click another, then the first option should still be selected. Instead what happens is that each time submit is pressed the 3 form values return to their default value.

How do i go about fixing that?

Cheers!
 
When the form is submitted is the value stored in a database?

If so then maybe you could check the db for the last submitted values for each user on the page the shows the form.

Also sometimes the browser will re-populate the form elements automagically when they just mash the back button.
 
Thanks, but is there a way to do it without writing to the db?

How about using an attribute like "onSubmit" is there anything I could do with that?

Cheers
 
When you do a submit using the Post method the values are all available in your Request.Form variables collection - like Request.Form("username"). When you reload the form collect that data
Code:
<%strUsername = Request.Form("username")%>
When you actually define the form use something like
Code:
<input type="text" id="username" name="username" maxlength="20" value="<%=StrUsername%>" />

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Hi Johnwm

thanks for that, its what I need although my variable keeps resetting for some reason, it kind works like this:

page1.asp
include form.asp (action=page1.asp)
display data

I guess it should be

form.asp (action=page1.asp)
page1.asp
display data
link back to form

make any sense?
 
how about something like:

Code:
<%
if request.form("SubmitButton") <> "" then 
  Dim bAllOK
  bAllOK = True

  'server-side form validation
  if Trim(Request.Form("Answer")) = "" then
    bAllOK = False
  elseif Not IsNumeric(Trim(Request.Form("Answer"))) then
    bAllOK = False
  elseif 1 = 0 then
    bAllOK = False
  end if


  'server-side form processing:
  if Trim(Request.Form("Answer")) <> "4" then
    bAllOK = False
  end if


  if bAllOK then
    server.transfer "display.asp"
  end if
end if
%>
<html>
 <body>
  <form method="post" action="page1.asp">
    What is 2 + 2? 
    <input type="text" name="Answer" value="<%= Request.Form("Answer")%>"
    <br>
    <input type="submit" name="SubmitButton" value="Test">
  </form>
 </body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top