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

How to display error message on the same form page??? 1

Status
Not open for further replies.

920506

Programmer
Jun 13, 2003
201
0
0
US
Hi,
After struggling with data disappering problem with "back" button on the form for a few days. I think displaying error message above the same form is way to avoid users using back button. Below the error message, the form are still there,editable, so user get chance to correct fields. How can I do with it. I have seen some web site does this way. just don't know how.
Betty
 
I use html forms (built using asp) with javascript. I validate the form and display error messages in a DIV. This does not require the page to be reloaded, does not erase anything in the fields, and you can put the DIV wherever you want in the page.

DIV:
<div id='layerErrMsg' align='center' style='position:absolute; width:605px; height:25px; left:0px; top:700px;'></div>

DISPLAY IN DIV:
document.all[&quot;layErrMsg&quot;].innerHTML = errMsg;

Now, this code is for Internet Explorer. The problem i have with using DIV is that writing to the div is different in IE than in NS4. Check on the net for code on how to do that.

Hope that helps.
 
The forms in ASP are stateless, meaning they don't remember their values as such you have to work with it. What you can do is the following:

<% Dim NAME
NAME = Request.Form(&quot;name&quot;)
%>

<form action=&quot;file.asp&quot; method=&quot;post&quot;>
Name: <input type=&quot;Text&quot; name=&quot;name&quot; value=&quot;<%=NAME%>&quot;>
</form>

When you first bring up the form in your browser the field name is empty.
Once you enter some input and submit the form it goes to file.asp, there
you can do your validity checking. When you press the back button the values will be filled in.

If you choose to do the error checking on the same page as the form, the value
will still be there because it's populated in the value property by <%=NAME%>

Hope it helps.

&quot;Taxes are the fees we pay for civilized society&quot; G.W.
 
Assuming that you have a form page and a processing page...Here's a simple example:

Formpage.asp

<%
strDate=request.querystring(&quot;strDate&quot;)
Missing=request.querystring(&quot;Missing&quot;)
NotDate=request.querystring(&quot;NotDate&quot;)
NotToday=request.querystring(&quot;NotToday&quot;)
if Missing=&quot;TRUE&quot; then
errMsg=&quot;<font color='#ff0000'>Date Can Not Be Blank. Please Enter a Date!</font>&quot;
ShowMsg=TRUE
END IF
If NotDate=&quot;TRUE&quot; then
errMsg=&quot;<font color='#ff0000'>&quot; & strDate & &quot; Is Not A Valid Date!</font>&quot;
ShowMsg=TRUE
End IF
If NotToday=&quot;TRUE&quot; then
errMsg=&quot;<font color='#ff0000'>&quot; & strDate & &quot; Is Not Today's Date!</font>&quot;
ShowMsg=TRUE
End IF
%>
<html><head><title>Form Page</title></head><body>
<form name=&quot;myForm&quot; action=&quot;processingPage.asp&quot; method=&quot;post&quot;>
Enter Today's Date
<br>
<input type=&quot;text&quot; name=&quot;strDate&quot; value=&quot;<%=strDate%>&quot;>
<%IF ShowMsg then%><%=errMsg%><%end if%>
<br>
<input type=&quot;submit&quot; name=&quot;btnSubmit&quot; value=&quot;Submit&quot;>
</form>
</body></html>

ProcessingPage.asp

<%
If request.form(&quot;strDate&quot;) <> &quot;&quot; THEN
strDate=request.form(&quot;strDate&quot;)
ELSE
response.redirect(&quot;formpage.asp?Missing=TRUE&quot;)
End If
If not isdate(strDate) then
response.redirect(&quot;formpage.asp?NotDate=TRUE&strDate=&quot; & strDate)
elseif CDate(strDate) <> Date() then
response.redirect(&quot;formpage.asp?NotToday=TRUE&strDate=&quot; & strDate)
End if

' Otherwise everything is OK and you can do your processing
response.write &quot;A-OK!&quot;

%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top