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

This sounds stupid..... But.......

Status
Not open for further replies.

DavidPook

Instructor
May 9, 2003
11
BR
What am i doing wrong with this IF statement ??


<%
if Name=&quot;&quot; then Msgbox &quot;please enter your name&quot;
End if
%>


I have a text box on my html page, and if the user doesnt fill anything in, I want a message box to appear to inform them that they must enter their name (or whatever)

I actually have 3 text boxes that MUST require their details

ie:
name
dept
ext

There is also a submit button that processes the information via an .asp page that then writes this information to an access database BUTit wont process if any one of those 3 fields are left blank.

Does any of this make any sense to anyone ????

I thought the statement was ok but it doesnt work !!!!.... Please could anyone tell me what i have done wrong ?

Thanks in advance guys [smile2]
 
should be document.name.length>0 and document.dept.length >0 etc
 
Ok,

so.....

<%
if document.Name.length=>0 then Msgbox &quot;please enter your name&quot;
End if
%>

Is this right?

Sorry for my thickness...... But i have been working with html and asp pages all day and so many of them that my head is starting to spin

Thanks for replying to my original message .... this is a great forum for beginners like me.

 
No - the problem is your end if line

When you write
If....Then....

it is considered to be a one-line statement and cannot have an end if....

Valid formats
If.....Then.....Else.....

If.....Then.....

If ..... Then
......
ELSE
......
END IF

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
OOpps - you can't have message boxes on the server side...

Your client-side JavaScript validation should look like this:

<script language=javascript>
function subForm(){
msg = &quot;&quot;
for (x=0; x<document.myForm.elements.length; x++){
if (document.myForm.elements[x].value == &quot;&quot;){
msg += &quot;\n- &quot; + document.myForm.elements[x].name
}
}
if (msg.length > 0){
alert(&quot;Please fill the follwing fields:&quot; + msg)
}
else{
document.myForm.submit()
}
}
</script>
<form name=&quot;myForm&quot;>
<input>
<input>
<input type=button onClick=&quot;subForm()&quot; value=&quot;Submit&quot;>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top