Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > how to stop executing if validation returns false

Reply
Thread Tools

how to stop executing if validation returns false

 
 
mak
Guest
Posts: n/a
 
      03-08-2008
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
 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      03-08-2008
On Mar 8, 10:55 pm, mak <mak1...@gmail.com> wrote:

> 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;
}
}
 
Reply With Quote
 
 
 
 
mak
Guest
Posts: n/a
 
      03-08-2008

>
> <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.
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      03-08-2008
mak wrote:
> [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
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      03-08-2008
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.

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



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
"def nothing=(data) false end" returns 'data' instead of 'false' IƱaki Baz Castillo Ruby 9 02-26-2009 09:38 PM
CustomValidator Returns False, but False is Ignored DJ ASP .Net 3 12-27-2007 10:29 AM
False positive, false intrusion, false alarm Nick Computer Security 3 04-26-2006 07:40 PM
How to stop form submit when onClick event returns false Randell D. Javascript 4 11-27-2003 04:54 AM



Advertisments