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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<a href='javascript:history.back()'>Back</a>

Status
Not open for further replies.

jcroft

Programmer
Aug 23, 2001
52
US
I have an ASP page that sends an email to someone...someone clicks on the link that sends them to this page...they fill out form but leave out an item...the error trap below brings up a page with a "Back" link...they click "Back" and their data they entered is lost...if they retype and still have an error...then click the "Back" button their data is NOT lost...

If Request.Form("Submit1") = "Process" then

'checking for blanks and invalid entries
If Len(Request.Form("whorespond")) = 0 then
Response.Write &quot;Please Enter your name.&quot; & &quot;<BR>&quot;
Response.Write&quot;<a href='javascript:history.back()'>Back</a>&quot;
Response.End
end if

What am I doing wrong?? I do not want the user to have to retype data.

Thank you.
 
Jcroft,

Do your error trap using client side JavaScript. That way, the form never leaves the browser until all of the data is validated. It really is the best way to validate.

Post the form here and I'll show you how to do it.. (Everything between and including the <form></form> tags.

ToddWW :)
 
You are too kind, thank you.

<FORM id=FORM1 name=FORM1 action=&quot;respondpage.asp?ID=<%=rs(&quot;ID&quot;)%>&quot; method=post>
<%

'this determines how much time passed before the customer got a response from us
Dim elapsedtime
intvar= (formatdatetime(now(),2))

Function DiffADate(theDate)
DiffADate = DateDiff(&quot;d&quot;,(rs(&quot;ComDate&quot;)),intvar)
End Function

If rs(&quot;ComDate&quot;) <> intvar then
elapsedtime=DiffADate(theDate)
Else
elapsedtime= 0
End If
rs(&quot;ElapsedTime&quot;) = elapsedtime
%>
<FONT SIZE=4><B>Customer Service Response Form<BR></font>
<HR>
<font color=&quot;#cc66cc&quot; size=4><input type=label id=elapsedtime value=<%=elapsedtime%> name=elapsedtime readonly size=5></font><font size=3> day(s) has elapsed since customer submitted this comment.</FONT>

<label type=text id=date name=respdate value=&quot;<%=FormatDateTime(Now(),2)%>&quot;>
<font size=2>Date: <%=FormatDateTime(Now(),1)%></font>
<HR>
<font size=3><B>Please enter your response to the customer comments below:</B></font>
<HR>

<Label id=text name=comdate>Date Submitted:
<font color=&quot;#6666cc&quot;><%=rs(&quot;ComDate&quot;)%></font>

<BR><label id=text4 >ID Number: <font color=&quot;#6666cc&quot;><%=rs(&quot;ID&quot;)%></font>

<BR><Label id=text1 value=&quot;<%=rs(&quot;fname&quot;)%>&quot; name=fname>First Name: <font color=&quot;#6666cc&quot;><%=rs(&quot;fname&quot;)%></font>

<BR><Label id=text2 value=&quot;<%=rs(&quot;lname&quot;)%>&quot; name=lname>Last Name: <font color=&quot;#6666cc&quot;><%=rs(&quot;lname&quot;)%></font>

<BR><Label id=text3 value=&quot;<%=rs(&quot;Email&quot;)%>&quot; name=email>Email Address: <font color=&quot;#6666cc&quot;><%=rs(&quot;Email&quot;)%></font>

<BR>
<HR>
If this section contains blanks, it is due to the customers preference.
<BR><Label id=text5 value=&quot;<%=rs(&quot;CompanyName&quot;)%>&quot; name=company>Company Name: <font color=&quot;#6666cc&quot;><%=rs(&quot;CompanyName&quot;)%></font>

<BR><Label id=text6 value=&quot;<%=rs(&quot;Address&quot;)%>)&quot; name=street>Street Address: <font color=&quot;#6666cc&quot;><%=rs(&quot;Address&quot;)%></font>

<BR><Label id=text8 value=&quot;<%=rs(&quot;City&quot;)%>&quot; name=city>City: <font color=&quot;#6666cc&quot;><%=rs(&quot;City&quot;)%></font>

<Label id=select1 value=&quot;<%=rs(&quot;State&quot;)%>&quot; name=state1>State: <font color=&quot;#6666cc&quot;><%=rs(&quot;State&quot;)%></font>

<Label id=text10 value=&quot;<%=rs(&quot;Zip&quot;)%>&quot; name=zip>Zip Code: <font color=&quot;#6666cc&quot;><%=rs(&quot;Zip&quot;)%></font>

<BR><Label id=text11 value=&quot;<%=rs(&quot;WorkPhone&quot;)%>&quot; name=phone>Phone Number: <font color=&quot;#6666cc&quot;><%=rs(&quot;WorkPhone&quot;)%></font>

<Label id=text value=&quot;<%=rs(&quot;URL&quot;)%>&quot; name=URL>URL Address: <font color=&quot;#6666cc&quot;><%=rs(&quot;URL&quot;)%></font>
<HR>

Customer comments and/or suggestions:

<BR><label id=label1 value=&quot;<%=rs(&quot;comments&quot;)%>&quot; name=comments>Comments:<BR><font color=&quot;#6666cc&quot;><%=rs(&quot;comments&quot;)%></font>

<BR>
<HR>
Please specify type of customer:
<INPUT type=radio id=radio1 value=&quot;C&quot; name=radio>Current Retailer

<INPUT type=&quot;radio&quot; id=radio2 value=&quot;N&quot; name=radio>New Retailer

<INPUT type=&quot;radio&quot; id=radio3 value=&quot;I&quot; name=radio>Individual

<BR>Recommended Storefront#1:
<INPUT id=store1 name=store1>
Storefront#2:<INPUT id=store2 name=store2>
Storefront#3:<INPUT id=store3 name=store3>

<BR>Your name goes here:
<input id=whorespond name=whorespond><BR>

<HR>
Greeting to Customer Goes Here(i.e.Dear Mr. Jones):<BR>

<input id=greeting name=greeting><BR>
<input type=hidden id=respdate name=respdate value=&quot;<% = FormatDateTime(Now(),2)%>&quot;>

Please enter your response to customer comments here and press &quot;Process&quot; button:

<BR><TEXTAREA id=TEXTAREA1 name=responsetocomments rows=10 cols=90>The body of your response goes here, the costomer's name and your name will automatically be entered.

<TR>
<TD><form method=post action=process>
<INPUT type=submit value=Process id=submit1 name=Submit1>
</form>
</TD>
<TD>
<form method=post action=CustCommentMenu.asp id=form2 name=form2>
<input type=&quot;submit&quot; name=menupage value=&quot;Back to Menu&quot;>
</form>
</TD>
<TD>
<form method=post action= id=form3 name=form3>
<input type=&quot;submit&quot; name=adminpage value=&quot;Back to Admin Page&quot;>
</FORM>
</TD>
<TD>
<!-- print -->
<script language=&quot;JavaScript&quot;><!--
if (window.print)
document.write('<form><input type=&quot;button&quot; value=&quot;Print&quot; onClick=&quot;window.print()&quot;><\/form>');
//--></script>
</TD>
</TR>
</TABLE>
</B>
</FONT>
</td>
</tr>
</table>
 
OK jCroft. Basic JavaScript validation.

First in order to send the form elements to a JavaScript function for validation before the form is submitted you're opening <form> tag needs to look like this.

<FORM id=FORM1 name=FORM1 action=&quot;respondpage.asp?ID=<%=rs(&quot;ID&quot;)%>&quot; method=post onSubmit=&quot;return form1Val();&quot;>

Now, I've noticed that you have multiple forms with multiple submit buttons, so I'm just going to provide you an example for validating form1. If you want to provide validation for the other forms, you'll have to write a seperate JavaScript function for each form and call that specific funtion in the opening <form> tag like I have done above.

OK, now you need to write the following code in between the <head> </head> tags of your HTML document. Like this.
Code:
<html>
<head>
<title>Some Page Title</title>
<script Language=&quot;JavaScript&quot;>
<!--
function form1Val() {
  if (document.form1.whorespond.value == &quot;&quot;) {
    window.alert(&quot;Please Enter Your Name&quot;)
    document.form1.whorespond.focus()
    return false
  }
  return true
}
//-->
</script>
</head>

What that function does is check the value of the whorespond input element and if it is empty, a Windows alert will appear with a message, the cursor will focus back on that element and the JavaScript will return a false parameter back to the onSubmit event handler which will in turn, stop the form from submitting. If the value is not empty, than that conditional block of code is passed over and the function will return a true parameter back to the onSubmit event handler which will go ahead and submit the form.

Try it out and let me know if you need further assistance. I think if you read over the JavaScript syntax, you'll see how we reference the element that we want to validate. Just remember on conditional if statements in JavaScript you need to use two == signs for comparison.

ToddWW :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top