vnmshenoy
02-05-2008, 08:16 AM
Hi guys,
This is my first post in this site....:)
I want to know the use of with statement.I read it in a book that we use it to save ourselves from typing....
example
frames[1].document.forms[0].address_field.value
can be written as
with(frames[1].document.forms[0])
{
name.value="";
address.value="";
etc..
}
Now see the code below...
<html>
<head>
<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{alert(alerttxt);return false;}
else {return true}
}
}function validate_form(thisform)
{
alert("hello");
with (thisform)
{
if (validate_required(email,"Email must be filled out!")==false)
{email.focus();return false;}
}
}
</script>
</head><body>
<form action="submitpage.htm"
onsubmit="return validate_form(this)"
method="post">
Email: <input type="text" name="email" size="30">
<input type="submit" value="Submit">
</form>
</body></html>
Above i want to know what i need to do to remove "with" clause.
if i replace it with below code
function validate_form(thisform)
{
alert("hello");
if (validate_required(email,"Email must be filled out!")==false)
{document.forms[0].email.focus();return false;}
}
i get an error which says
'email' is undefined.....
TELL ME HOW CAN I REMOVE WITH CLAUSE FROM HERE.....
This is my first post in this site....:)
I want to know the use of with statement.I read it in a book that we use it to save ourselves from typing....
example
frames[1].document.forms[0].address_field.value
can be written as
with(frames[1].document.forms[0])
{
name.value="";
address.value="";
etc..
}
Now see the code below...
<html>
<head>
<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{alert(alerttxt);return false;}
else {return true}
}
}function validate_form(thisform)
{
alert("hello");
with (thisform)
{
if (validate_required(email,"Email must be filled out!")==false)
{email.focus();return false;}
}
}
</script>
</head><body>
<form action="submitpage.htm"
onsubmit="return validate_form(this)"
method="post">
Email: <input type="text" name="email" size="30">
<input type="submit" value="Submit">
</form>
</body></html>
Above i want to know what i need to do to remove "with" clause.
if i replace it with below code
function validate_form(thisform)
{
alert("hello");
if (validate_required(email,"Email must be filled out!")==false)
{document.forms[0].email.focus();return false;}
}
i get an error which says
'email' is undefined.....
TELL ME HOW CAN I REMOVE WITH CLAUSE FROM HERE.....