how to stop executing if validation returns false

M

mak

hi,
i'm doing a validation in a JSP page. in two fields
function valli()
{
valid = true;

if ( document.all['lecture_held'].value == "")
{
alert("Please Select total Lecture Cunducted");
document.all['lecture_held'].focus();
valid = false;
}
if ( document.all['att'].value == "")
{
alert("Please Enter Students Attendance");
document.all['att'].focus();
valid = false;
}
return valid;
}

when it returns false then it executes the jsp code...

what should i do so that when it return true then only it should
execute the jsp code....

please help

thank you
 
V

VK

what should i do so that when it return true then only it should
execute the jsp code....

<form onsubmit="return valli(this)">

with valli returning false or true respectively.

P.S.
if ( document.all['lecture_held'].value == "")

Despite document.all collection became an alternative standard to
document.getElementById, some browsers support it only in so called
"quirk mode" caused by a particular DOCTYPE declaration or by the
absence of such. You don't want to break your script by simply
switching to the strict mode, so you may want to use standard tools
instead.

<form onsubmit="return valli(this)" ...

function valli(frm) {
if (frm.lecture_held.value == "") {
frm.lecture_held.focus();
return false;
}
else if {
// ...
}
else if {
// ...
}
else {
return true;
}
}
 
M

mak

<form onsubmit="return valli(this)" ...

function valli(frm) {
 if (frm.lecture_held.value == "") {
  frm.lecture_held.focus();
  return false;
 }
 else if {
  // ...
 }
 else if {
  // ...
 }
 else {
  return true;
 }



}


even using like this its submiting the value, Even though I'm not
giving any value to the text box.
 
T

Thomas 'PointedEars' Lahn

mak said:
[VK wrote:]
<form onsubmit="return valli(this)" ...

function valli(frm) {
if (frm.lecture_held.value == "") {
frm.lecture_held.focus();
return false;
}
else if {
// ...
}
else if {
// ...
}
else {
return true;
}
}

even using like this its submiting the value, Even though I'm not
giving any value to the text box.

That is highly unlikely, you must have done something different to this.
Make sure that you always return a value from valli(), that you actually
have a `return' statement in the `onsubmit' attribute, and that you are
submitting using a submit button (`<input type="submit" ...>' or `<input
type="image" ...>'), not a click button (`<input type="button" onclick="..."
....>').


Please don't trim the attribution line next time.


PointedEars
 
E

Evertjan.

mak wrote on 08 mrt 2008 in comp.lang.javascript:
hi,
i'm doing a validation in a JSP page. in two fields

A Java Server Page?

Java has nothing to do with Javascript.

function valli()
{
valid = true;

if ( document.all['lecture_held'].value == "")
{
alert("Please Select total Lecture Cunducted");
document.all['lecture_held'].focus();
valid = false;
}
if ( document.all['att'].value == "")
{
alert("Please Enter Students Attendance");
document.all['att'].focus();
valid = false;
}
return valid;
}

when it returns false then it executes the jsp code...

Highly improbable, since the JSP code would be running on the server,
and the above javascript on the vlient.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top