I am validating a html form. On submit I have a functions like the one below.
I have seen examples like this, which is why I tried using “with but no documentation on when it’s best to use “with or what it’s really doing. I would also like to know alterative methods of doing a check like this.

Is “with just a glorified “if?

Function valForm(data)
{
   With(data)
   {
       If(…)
      {
          Alert…
          Return false;
      }
      Else
      {
          Return true;
      }
}

Recommended Answers

All 2 Replies

nevermind!
the keyword with can be used to associate all references to a method or property.

a = Math.cos(Math.PI/4);
b = Math.pow(3,5);

usinig keyword with this becomes

with (Math)
{
a = cos(PI/4);
b = pow(3,5);
}

It is my opinion that the keyword 'with' should never be used. As far as I am aware, it comes from VB. And is not backwards compatible with older versions of JavaScript in Mozilla/Gecko based browsers.

In my opinion, it is bad style and should not be used.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.