Click to See Complete Forum and Search --> : Form input error
Pooter8D
07-16-2003, 10:33 AM
what is the fastest and easiest way to do a check for form fields to see if they are correct and then pop up a message box with the appropriate error..
ex. If name field is blank and when user hits submit btn
if form.namefield == ""
then MessageBox("Name field is Blank!")
quick c++... sorry :)
thx
Pooter8D
07-18-2003, 01:38 PM
well is there a way to do in asp??? i think this is the right place to ask that??
i only used that quick c becuase thats what i'm most confortable with to pump out a quicky example of what i want... just need it in in asp
CrazyGaz
07-18-2003, 06:17 PM
Dave I know you'll hate me.
<script language="javascript">
function validate() {
if (document.form1.username.value.length == 0) {
alert("you must enter a user name");
return false;
}
}
</script>
then in the HTML
<form OnSubmit="validate()" name="form1">
<input type="text" name="username">
<input type="submit" value="submit">
</form>
Gaz
CrazyGaz
07-18-2003, 06:27 PM
<% if usrnamechars < 3 then
response.write "your username must be at least 3 characters"
call applyForm
elseif passwordchars < 3 then
response.write "your password must be at least 3 characters"
call applyForm %>
<% sub applyForm %>
<form action=addinfo.asp method="post">
<table>
<tr>
<% if usrnamechars < 3 then %>
<td width="100"><font color="red">Name:</font> </td>
<% else %>
<td width="100">Name: </td>
<% end if %>
<td><input type="text" name="user_name" value="<%=ausername%>"></td>
<tr>
<% if passwordchars < 3 then %>
<td><font color="red">Password:</font> </td>
<%else%>
<td>Password:</td>
<%end if%>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td><input type="submit" value="submit"></td>
</tr>
</table>
</form>
<% end sub %>
how I would do it in ASP :) (proving I can :p)
Pooter8D
07-20-2003, 10:38 AM
thx CrazyGaz..
sorry Dave i was not aware that asp could not access a messagebox
Pooter8D
07-22-2003, 09:02 AM
crazygaz i got a quicky for you
i ended up using the javascript code you gave me.. it works great but if there is an error when the person clicks OK all the fields become empty. I dont want it.. is there a simplier way to keep existing values or should i just feed them in manually???
thx