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!

Checking text area boxes for null value

Status
Not open for further replies.

avaffa

Programmer
Jun 22, 2001
86
0
0
US
I am trying to check whether users enter info into specific fields (validation). The code I developed, checks the first field of the form only, which is a text field. But when I check for a null value in a text area box (named "desc") or other text boxes, I get the error message regardless of whether it's null or not. Please help! Below is my code:

<script>
function goback(){
history.go(-1);
}
</script>

<% S_ID = Request.Form("S_ID") %>
<% topic = Request.Form("topic") %>
<% desc2 = Request.Form("desc") %>
<% headers = Request.Form("headers") %>
<% other_header = Request.Form("other_header") %>
<% av = Request.Form("av") %>
<% min_time = Request.Form("min_time") %>

<html>
<head>
<title>2004 Speakers Bureau Updates - Topics</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">

<% if topic="" then %>

<div align="center"><img src="images/TOP4.GIF" width="580" height="166" align="middle"><BR>
<BR>
</div>

<table width="600" border="0" cellpadding="5" align="center">
<tr bgcolor="#FFFFCC">

<td colspan="2"> <font face="Arial, Helvetica, sans-serif" size="3"> <font color="#FF0000">You
must enter a <b>topic</b>.</font> Please click <a href="javascript:goback()">here</a>
to return to the form.</font></td>
</tr>
<tr>
<td>

</td>
<td>&nbsp;</td>
</tr>
</table>
<% else if desc2="" then %>

<div align="center"><img src="images/TOP4.GIF" width="580" height="166" align="middle"><BR>
<BR>
</div>

<table width="600" border="0" cellpadding="5" align="center">
<tr bgcolor="#FFFFCC">

<td colspan="2"> <font face="Arial, Helvetica, sans-serif" size="3"> <font color="#FF0000">You
must enter a <b>description</b>.</font> Please click <a href="javascript:goback()">here</a>
to return to the form.</font></td>
</tr>
<tr>
<td>

</td>
<td>&nbsp;</td>
</tr>
</table>
<% else %>


<%
' Setting variables
Dim con, sql_update, data_source

data_source = "access"
sql_update = "update topics set topic = '" &replace(Request.Form("topic"),"'","''")& "', " &_
"description = '" &replace(Request.Form("desc"),"'","''")& "', " &_
"headers = '" &replace(Request.Form("headers"),",",";")& "', " &_
"av_requirements = '" &replace(Request.Form("av"),",",";")& "', " &_
"deleted = '" &replace(Request.Form("delete"),"'","''")& "', " &_
"min_time = '" &replace(Request.Form("min_time"),"'","''")& "', " &_
"revision_date = '" &Request.Form("date")& "', " &_
"other_header = '" &replace(Request.Form("other_header"),"'","''")& "' where T_ID = '" &Request.Form("T_ID")& "'"

' Creating the Connection Object and opening the database
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source

' Executing the sql update code
con.Execute sql_update

' Done. Now Close the connection
con.Close
Set con = Nothing
%>
<%
Set rs = Server.CreateObject("ADODB.Recordset")

rs.MaxRecords=1

S_ID = Request.Form("S_ID")
T_ID = Request.Form("T_ID")
first_name = Request.Form("first_name")
last_name = Request.Form("last_name")
number = Request.Form("num")

if S_ID = "" then
flag=0
else
flag=1
end if

q = "SELECT [recno], [S_ID], [T_ID], [first_name], [last_name], [topic], [description], [headers] FROM sbupdates2 WHERE S_ID LIKE '" &S_ID& "' AND [recno] > " &number& " ORDER BY [recno] ASC"
rs.Open q, "DSN=access;"
%>


<% if flag=0 then
Response.Write("You must select a name.") %>

<% else if rs.EOF then %>
<div align="center"><img src="images/TOP4.GIF" width="580" height="166"><BR>
<BR>
</div><form method="POST" name="end_list" action="blank2.asp">
<input type="hidden" name="S_ID" value="<%=Request.Form("S_ID")%>">
<table width="600" border="0" cellpadding="5" align="center">
<tr>
<td height="33" bgcolor="#FFFFCC"><font face="Arial, Helvetica, sans-serif" size="3">You
have reviewed and/or updated all topics currently listed in the Speakers
Bureau database. Do you wish to add a new topic? </font></td>
</tr>
<tr>
<td>
<div align="center">
<input type="submit" name="Submit5" value="Yes">
<input type="submit" name="Submit5" value="No">
</div>
</td>
</tr>
</table>
</form>

<% else %>

<form method="POST" name="topics" action ="topics.asp">
<div align="center">
</div>
<p>
<input type="hidden" name="S_ID" value="<%=rs("S_ID")%>">
<input type="hidden" name="T_ID" value="<%=rs("T_ID")%>">
<input type="hidden" name="first_name" value="<%=rs("first_name")%>">
<input type="hidden" name="last_name" value="<%=rs("last_name")%>">
<input type="hidden" name="num" value="<%=rs("recno")%>">
<input type="hidden" name="date" value="<%=date()%>">
<input type="hidden" name="desc2" value="<%=rs("description")%>">
<img src="images/TOP4.GIF"><BR>
<BR>
</p>
<table width="600" border="0" cellpadding="5" align="center">
<tr>
<td><font face="Arial, Helvetica, sans-serif" size="2">Please review the
following topic and make any necessary corrections directly in the boxes.
Please add a 1-2 sentence description if one is not listed. You can
use the &quot;copy&quot; and &quot;paste&quot; functions to update your
information if it is contained in another application. If you would
like to remove this topic from the Speakers Bureau, please select &quot;Delete
this topic from the Speakers Bureau&quot; at the bottom of the page.</font></td>
</tr>
</table>
<br>

<table width="600" border="0" cellpadding="5" align="center" bgcolor="#FFFFCC">
<tr valign="top" bgcolor="#006633">
<td colspan="4"><font size="5" face="Arial, Helvetica, sans-serif"><b><font color="#FFFFCC">Topic(s)
</font></b></font></td>
</tr>
<% y=0
while (NOT rs.EOF) and (y<1)%>
<%T_ID = rs("T_ID").value %>
<% description = rs("description") %>

<tr valign="top">
<td width="192"><b><font size="2" face="Arial, Helvetica, sans-serif"><br>
Topic:</font></b></td>
<td colspan="3"><font size="2" face="Arial, Helvetica, sans-serif"> <br>
<input type="text" name="topic" value="<%=rs("topic")%>" size="70">
</font></td>
</tr>
<tr valign="top">
<td width="192"><b><font face="Arial, Helvetica, sans-serif" size="2">Description:</font></b></td>
<td colspan="3"><font size="2" face="Arial, Helvetica, sans-serif">
<textarea rows="10" cols="60" wrap="hard" name="desc"><%=Response.Write(description)%></textarea>
</font></td>
</tr>
<tr valign="top" bgcolor="#FFFFCC">
<td width="192"><font face="Arial, Helvetica, sans-serif" size="2"><b>Minimum
Time Required:</b></font></td>
<td width="132" valign="bottom">
<input type="text" name="min_time" size="8">
<font face="Arial, Helvetica, sans-serif" size="2">min.</font> </td>
<td width="132">&nbsp;</td>
<td width="117">&nbsp;</td>
</tr>
<tr valign="top" bgcolor="#FFFFCC">
<td width="192"><b><font size="2" face="Arial, Helvetica, sans-serif">Heading(s):<br>
</font></b><font size="2" face="Arial, Helvetica, sans-serif"><i>(check
all that you wish your topic to appear under)</i> </font></td>
<td width="132"><font size="2" face="Arial, Helvetica, sans-serif"> <font size="1">
<input type="checkbox" name="headers" value="Aging">
Aging<br>
<input type="checkbox" name="headers" value="The Arts">
The Arts<br>
<input type="checkbox" name="headers" value="Bankruptcy">
Bankruptcy<br>
<input type="checkbox" name="headers" value="Business">
Business<br>
<input type="checkbox" name="headers" value="Career Development">
Career Development<br>
<input type="checkbox" name="headers" value="Childhood Development">
Childhood Development<br>
<input type="checkbox" name="headers" value="Communication">
Communication<br>
<input type="checkbox" name="headers" value="Computers and Computing">
Computers and Computing<br>
<input type="checkbox" name="headers" value="Conflict Resolution">
Conflict Resolution<br>
<input type="checkbox" name="headers" value="Creditors Rights">
Creditors Rights<br>
<input type="checkbox" name="headers" value="Crime/Violence">
Crime/Violence<br>
<input type="checkbox" name="headers" value="Cultural Issues">
Cultural Issues<br>
<input type="checkbox" name="headers" value="Driving">
Driving<br>
<input type="checkbox" name="headers" value="Economic Development">
Economic Development<br>
<input type="checkbox" name="headers" value="Education and Teaching">
Education and Teaching<br>
<input type="checkbox" name="headers" value="Engineering">
Engineering<br>
</font><font face="Arial, Helvetica, sans-serif"><font size="2" face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font size="2" face="Arial, Helvetica, sans-serif"><font size="1">
<input type="checkbox" name="headers" value="Environment">
Environment<br>
<input type="checkbox" name="headers" value="Estate Planning">
Estate Planning</font></font><font size="1"><br>
</font><font face="Arial, Helvetica, sans-serif"><font size="2" face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font size="2" face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font size="1">
<input type="checkbox" name="headers" value="Ethics">
Ethics</font></font></font></font></font></font><font size="1"> <br>
</font></font></font></font><font size="1"><br>
</font><font face="Arial, Helvetica, sans-serif"><font size="1"> </font></font><font size="1"><br>
</font></font></td>
<td width="132"> <font face="Arial, Helvetica, sans-serif"> <font size="1">
</font><font size="2" face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font size="1">
</font><font size="2" face="Arial, Helvetica, sans-serif"><font size="1">
</font></font></font></font><font size="1"> </font><font size="2" face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font size="2" face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font size="1">
</font></font><font size="1"> </font></font><font size="1"></font></font><font size="1"></font></font><font size="1">
<input type="checkbox" name="headers" value="Exercise and Sports">
Exercise and Sports<br>
<input type="checkbox" name="headers" value="George Mason University">
George Mason University<br>
<input type="checkbox" name="headers" value="Government">
Government<br>
<input type="checkbox" name="headers" value="Health/Nutrition">
Health/Nutrition<br>
<input type="checkbox" name="headers" value="History">
History<br>
<input type="checkbox" name="headers" value="Human Resource/Management/Personnel">
Human Resource Management/Personnel<br>
<input type="checkbox" name="headers" value="International Business">
International Business<br>
<input type="checkbox" name="headers" value="Internet">
Internet<br>
<input type="checkbox" name="headers" value="Language">
Language<br>
<input type="checkbox" name="headers" value="Law Enforcement">
Law Enforcement<br>
<input type="checkbox" name="headers" value="Literature/Poetry">
Literature/Poetry<br>
<input type="checkbox" name="headers" value="Management">
Management<br>
<input type="checkbox" name="headers" value="Math and Statistics">
Math andStatistics<br>
<input type="checkbox" name="headers" value="Media">
Media<br>
<input type="checkbox" name="headers" value="Nonprofit Organizations and Charities">
Nonprofit Organizations and Charities<br>
<input type="checkbox" name="headers" value="Parenting">
Parenting<br>
</font><font face="Arial, Helvetica, sans-serif"><font size="1"> </font><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font size="1">
<input type="checkbox" name="headers" value="Philosophy">
Philosophy </font></font></font><font size="1"><br>
<input type="checkbox" name="headers" value="Politics">
Politics</font></font><font size="1"> </font></font></font><font size="1"></font></font><font size="1"><br>
</font><font face="Arial, Helvetica, sans-serif"><font size="1"> </font></font></font><font size="1">
</font></font></td>
<td width="117"> <font face="Arial, Helvetica, sans-serif"> <font size="1">
</font><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font size="1">
</font><font face="Arial, Helvetica, sans-serif"><font face="Arial, Helvetica, sans-serif"><font size="1">
</font></font></font></font></font></font><font size="1">
<input type="checkbox" name="headers" value="Psychology">
Psychology<br>
<input type="checkbox" name="headers" value="Public Policy and the Law">
Public Policy and the Law<br>
<input type="checkbox" name="headers" value="Public Speaking">
Public Speaking<br>
<input type="checkbox" name="headers" value="Real Estate">
Real Estate<br>
<input type="checkbox" name="headers" value="Regional Issues">
Regional Issues<br>
<input type="checkbox" name="headers" value="Religion">
Religion<br>
<input type="checkbox" name="headers" value="Research">
Research<br>
<input type="checkbox" name="headers" value="Science and Technology">
Science and Technology<br>
<input type="checkbox" name="headers" value="Security">
Security<br>
<input type="checkbox" name="headers" value="Social Issues">
Social Issues<br>
<input type="checkbox" name="headers" value="Stock Market">
Stock Market<br>
<input type="checkbox" name="headers" value="Taxes">
Taxes<br>
<input type="checkbox" name="headers" value="Terrorism">
Terrorism<br>
<input type="checkbox" name="headers" value="Transportation">
Transportation<br>
<input type="checkbox" name="headers" value="Women">
Women<br>
<input type="checkbox" name="headers" value="World Issues">
World Issues<br>
<br>
Other<br>
<input type="text" name="other_header" size="20">
</font></font></td>
</tr>
<tr valign="top">
<td width="192">
<div align="left"><b><font size="2" face="Arial, Helvetica, sans-serif">A/V
</font></b><font size="2" face="Arial, Helvetica, sans-serif"><b>Requirement(s):</b></font><b><font size="2" face="Arial, Helvetica, sans-serif"><br>
</font></b><font size="2" face="Arial, Helvetica, sans-serif"><i>(check
all that apply)</i> </font></div>
</td>
<td width="132"> <font face="Arial, Helvetica, sans-serif"> <font size="1">
<input type="checkbox" name="av" value="$/Piano">
Fee for Accompanist and Piano<br>
<input type="checkbox" name="av" value="FC">
Flip Chart<br>
<input type="checkbox" name="av" value="Web">
Internet Access<br>
<input type="checkbox" name="av" value="PC/LCD/S">
Laptop (with PowerPoint), LCD Projector, and Screen</font></font></td>
<td width="132"> <font face="Arial, Helvetica, sans-serif"> <font size="1">
<input type="checkbox" name="av" value="LCD/S">
LCD Projector and Screen (Speaker provides own laptop)<br>
<input type="checkbox" name="av" value="S">
Screen (Speaker provides own equipment)<br>
<input type="checkbox" name="av" value="OP/S">
Overhead Projector and Screen</font></font></td>
<td width="117"> <font face="Arial, Helvetica, sans-serif"> <font size="1">
<input type="checkbox" name="av" value="SP/S">
Slide Projector and Screen<br>
<input type="checkbox" name="av" value="TR">
Tape Recorder<br>
<input type="checkbox" name="av" value="TV/VCR">
TV and VCR</font></font></td>
</tr>
<tr valign="top">
<td colspan="4">&nbsp;</td>
</tr>
<tr valign="top">
<td>&nbsp; </td>
<td colspan="3">
<input type="checkbox" name="delete" value="Yes">
<b><font face="Arial, Helvetica, sans-serif" size="3">DELETE THIS TOPIC
FROM THE SPEAKERS BUREAU.</font></b></td>
</tr>

<%num=rs("recno").value%>
<%rs.MoveNext
y=y+1
wend
%>
</table>


<%if y>=1 then %>
<div align="center">
<p>
<input type="submit" name="Submit3" value="Next &gt;&gt;">
<% else %>
End of List
<%end if%>
</p>
</div>
</form>
<% end if %><%end if%><%end if %><% end if %></body>
</html>


 
what error are you getting??

I did notice this though:
Code:
<textarea rows="10" cols="60" wrap="hard" name="desc"><%=Response.Write(description)%></textarea>

you have <%=Response.Write()%> but the = is shorthand for Response.Write so you should take it out.

Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
The error message I created when a particular field is empty:

<% if topic="" then %>

<div align="center"><img src="images/TOP4.GIF" width="580" height="166" align="middle"><BR>
<BR>
</div>

<table width="600" border="0" cellpadding="5" align="center">
<tr bgcolor="#FFFFCC">

<td colspan="2"> <font face="Arial, Helvetica, sans-serif" size="3"> <font color="#FF0000">You
must enter a <b>topic</b>.</font> Please click <a href="javascript:goback()">here</a>
to return to the form.</font></td>
</tr>
<tr>
<td>

</td>
<td>&nbsp;</td>
</tr>
</table>
 
sorry i didnt read your post properly - I should have noticed that.

Does this form post to itself? If not, can you show the code where the <input name="topic"... is written. I can see <input name="topic"... in the form above and that looks fine.

Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
Yes, the form submits to itself.
 
not convinced this will fix your immediate problem but I also noticed this:
Code:
<% else if desc2="" then %>
should be
Code:
<% elseif desc2="" then %>

Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
No, if I replace <% if "topic = "" then %> with any other field name, then it still doesn't work. Even if I'm checking for that field only. It's something about the topic field. The code will not work for all other fields.
 
Two things immediately come to mind. First, I would try to Response.Write your values (e.g. - "topic") before you attempt to use your if/then statement to see what you are testing against.

Also, your original post stated that you were testing to see if it was null. If you are trying to determine if it is null, then you should use the IsNull() function. Your code indicates that you are actually testing for an empty string. Small thing, but just thought I'd mention it.

------------------------------------------------------------------------------------------------------------------------
"The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair."
--Dou
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top