• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

My if statement does not work correctly?

 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't forget your semicolons!
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

you are not looking at the value and AND in JavaScript is &&
do it this way
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...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 ]
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ah, sorry that was just a typo....
that extra val should not be there!!
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
cool thanks
Davy
 
Quick! Before anybody notices! Cover it up with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic