The moose likes HTML, CSS and JavaScript and the fly likes My if statement does not work correctly? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "My if statement does not work correctly?" Watch "My if statement does not work correctly?" New topic
Author

My if statement does not work correctly?

Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
Hey people,
I have this follwing HTML file, and it displays fine but it is supposed to clear the form if I only input one or none of the fields, the webserver is a fake address in the ACTION attribute of the form, but it is supposed to show that if not all the fields are entered then the form is supposed to clear itself, have I done something wrong.
remember, I am just learning JavaScript.

Davy
p.s. some words may not be spelled correctly as it cannot be included in this site.


How simple does it have to be???
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
Don't forget your semicolons!


Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003

you are not looking at the value and AND in JavaScript is &&
do it this way
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
Tom,
semicolons in JavaScript mean nothing at all! It is good practice to use them, but the script works the same with or without them!
Eric
Chris Baron
Ranch Hand

Joined: Mar 21, 2003
Posts: 1028
...and the second "&" neither!
if(thisform.u_name!=" " && thisform.pwd!=" ")
cb
<edit>Ooops Eric was faster </edit>
[ April 15, 2004: Message edited by: Chris Baron ]
Winston Smith
Ranch Hand

Joined: Jun 06, 2003
Posts: 136
semicolons in JavaScript mean nothing at all!

Haha, you know how long it took me to realize this? Well, I'm not going to answer for fear of embarassment/banishment from the Ranch forever. Javascript is such an interesting creature...I've often done things which were in complete opposition to standard programming practice.
Go ahead and throw some strings in the pot, then some floats and maybe some arrays...stir it up and the sit back at watch code that has no business working anywhere else in the programming world, run like a charm.


for (int i = today; i < endOfTime; i++) { code(); }
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
hey thanks for the reply,
Tom, I already know about the semicolons, Eric helped me out on this a few weeks ago, but thanks anyway.
Eric

if(thisform.u_nameval.value.length > 0 && thisform.pwd.value.length > 0)

I noticed that i can also do it like:
if(thisform.u_name.value.length > 0 && thisform.pwd.value.length > 0)
what is the difference taking out the val after name??? thanks for helping to make it work.
I forgot about the & being bitwise and && being logical!!! silly me
Davy
[ April 15, 2004: Message edited by: Davy Kelly ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
without the name you are calling the object. A browser like IE will usuually figure out what you mean, other browsers will error out.

with the object you have a lot of other attributes you can call: style, name, title, etc...
Eric
[ April 15, 2004: Message edited by: Eric Pascarello ]
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
Hi Eric,
I am not sure I got you correctly, or maybe I did not explain my self clearly
if(thisform.u_nameval.value.length > 0 && thisform.pwd.value.length > 0)
I have bolded the part which I was talking about.
My browser is firefox v0.8 and the bold part included or not works fine, so what is the bold part dooing?
Davy
[ April 16, 2004: Message edited by: Davy Kelly ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
ah, sorry that was just a typo....
that extra val should not be there!!
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
cool thanks
Davy
 
 
subject: My if statement does not work correctly?
 
Threads others viewed
Unhide the text field
Passing values through html
embedded js file in doGet
Can't access HTML form page in browser
HTTP status 500
developer file tools