Jump to content

form validation


timeyyy_da_man
 Share

Recommended Posts

The keyword with (not sure if it's classed as a function...) uses the syntax:

with(object){/*some script here*/]}

and is for changing the scope of the script enclosed in the curly braces. i.e: all objects referenced or created within the curly braces will be children of the object set as the parameter of with; with(object). e.g:

with(document){  write('hello bobafet.');}

would write the string "hello bobafet" to the page, whereas you could use:

document.write('hello bobafet');

The simple reason for the with() 'function' is to make it easier to perform many actions under one scope without having to reference it in various lines of code (or at least that's how I've come to understand it). Hope this helps.

Link to comment
Share on other sites

NF2K has it right. I don't use "with" very often, but I can see the benefit of using it from time to time.Just to provide another example, rather than:

var div = document.getElementById("myDiv");div.style.backgroundColor = "#ff8c00";div.style.color = "#000000";div.style.width = "400px";div.style.height = "400px";div.style.borderColor = "#000000";div.style.borderWidth = "2px";div.style.borderStyle = "solid";

You can use "with" to make it like this:

var div = document.getElementById("myDiv");with(div.style){	backgroundColor = "#ff8c00";	color = "#000000";	width = "400px";	height = "400px";	borderColor = "#000000";	borderWidth = "2px";	borderStyle = "solid";}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...