Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > How to stop a validation function from executing after it encounters an error?

Reply
Thread Tools

How to stop a validation function from executing after it encounters an error?

 
 
effendi@epitome.com.sg
Guest
Posts: n/a
 
      02-27-2005
I wrote a very simple validation fucntion to check if all fields are
entered properly in a dialog box before returning this the values to
the parent form. The validation works finr however, I am not sure if I
am doing this correctly. For example if the telephone number field is
empty, the alert box appear telling the users to enter the telephone
number. However, once I click OK. the script appear to run and I get an
error message in the "dialog box window". What I would like to do is
let the user click ok and return back to the problem field. Below is my
code.

var thisdoc=document.forms[0]
var Role=getSelectedText(thisdoc.Role)
var MemberLookup=thisdoc.MemberLookup.value

if(Role==">>>Select Role") {
alert("Please select a role for this Team member")
thisdoc.Role.focus();
return
}

if (Role.substring(0,2)=="01" && thisdoc.TeamLeadAppt.value=="Y"){
alert("You can appoint only one person as Team Leader")
}

var ContactNo=thisdoc.ContactNumber.value

if(ContactNo.value==" ") {
alert("Please enter a Contact Number Team member")
thisdoc.ContactNumber.focus();
return;
}
if(ContactNo.length!= {
alert("Please enter a valid 8 digit telephone number this Team
member")
thisdoc.Role.focus();
return;
}
if(ContactNo.length!= {
alert("Please enter a valid 8 digit telephone number this Team
member")
thisdoc.Role.focus();
return;
}

window.opener.teamSelectionCallback(MemberLookup,R ole,ContactNo)
window.close()

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      02-27-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I wrote a very simple validation fucntion to check if all fields are
> entered properly in a dialog box before returning this the values to
> the parent form. The validation works finr however, I am not sure if I
> am doing this correctly. For example if the telephone number field is
> empty, the alert box appear telling the users to enter the telephone
> number. However, once I click OK. the script appear to run and I get an
> error message in the "dialog box window". What I would like to do is
> let the user click ok and return back to the problem field. Below is my
> code.
>
> var thisdoc=document.forms[0]
> var Role=getSelectedText(thisdoc.Role)
> var MemberLookup=thisdoc.MemberLookup.value
>
> if(Role==">>>Select Role") {
> alert("Please select a role for this Team member")
> thisdoc.Role.focus();
> return
> }


Taking a guess that you are running the validation using
onsubmit, then use:

return false;

and in your onsubmit:

onsubmit="return validationFun();"

to ensure the return value is passed to the form. That will stop
the form submitting when the validation fails. If all goes OK,
then just let the script end, successful completion will return
true.

[...]

--
Rob
 
Reply With Quote
 
 
 
 
Robert Mark Bram
Guest
Posts: n/a
 
      02-27-2005
Hello,

Are you trying to say that the script is entering more than one of your if
statements?

Is all of the code below in a single function?

Rob



<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>I wrote a very simple validation fucntion to check if all fields are
> entered properly in a dialog box before returning this the values to
> the parent form. The validation works finr however, I am not sure if I
> am doing this correctly. For example if the telephone number field is
> empty, the alert box appear telling the users to enter the telephone
> number. However, once I click OK. the script appear to run and I get an
> error message in the "dialog box window". What I would like to do is
> let the user click ok and return back to the problem field. Below is my
> code.
>
> var thisdoc=document.forms[0]
> var Role=getSelectedText(thisdoc.Role)
> var MemberLookup=thisdoc.MemberLookup.value
>
> if(Role==">>>Select Role") {
> alert("Please select a role for this Team member")
> thisdoc.Role.focus();
> return
> }
>
> if (Role.substring(0,2)=="01" && thisdoc.TeamLeadAppt.value=="Y"){
> alert("You can appoint only one person as Team Leader")
> }
>
> var ContactNo=thisdoc.ContactNumber.value
>
> if(ContactNo.value==" ") {
> alert("Please enter a Contact Number Team member")
> thisdoc.ContactNumber.focus();
> return;
> }
> if(ContactNo.length!= {
> alert("Please enter a valid 8 digit telephone number this Team
> member")
> thisdoc.Role.focus();
> return;
> }
> if(ContactNo.length!= {
> alert("Please enter a valid 8 digit telephone number this Team
> member")
> thisdoc.Role.focus();
> return;
> }
>
> window.opener.teamSelectionCallback(MemberLookup,R ole,ContactNo)
> window.close()
>



 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      02-27-2005
JRS: In article <(E-Mail Removed) .com>,
dated Sun, 27 Feb 2005 02:33:58, seen in news:comp.lang.javascript,
(E-Mail Removed) posted :

>if(ContactNo.length!= {
> alert("Please enter a valid 8 digit telephone number this Team
>member")


if (!/^\d{8}$/.test(ContactNo)) {
alert("Please enter a valid 8 digit telephone number for this Team member")

should be considerably better.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      02-28-2005
JRS: In article <42235315_1@127.0.0.1>, dated Mon, 28 Feb 2005
11:21:25, seen in news:comp.lang.javascript, Effendi Baba
<(E-Mail Removed)> posted :
>
>Thanks for correcting the error message but what's does your test
>function do? Does it check the number for valid characters only and that
>it should only be 8 character long?


It tests for an 8 decimal digit string, to match the error message. It
does not check that the number is telephonically appropriate; it accepts
all of 00000000 to 99999999, and nothing else.

See <URL:http://www.merlyn.demon.co.uk/js-valid.htm>.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      03-02-2005
JRS: In article <42258fca$1_1@127.0.0.1>, dated Wed, 2 Mar 2005
04:04:58, seen in news:comp.lang.javascript, Effendi Baba
<(E-Mail Removed)> posted :

Please learn how to format news replies; start by reading the newsgroup
FAQ.

>Thank you very much for this test. I think it will be useful in other
>situation as well. Could you lead me to a resource that could help me
>understand how to construct this test?


If what I have already given you is not enough, I can help no further.

>*** Sent via Developersdex http://www.developersdex.com ***
>Don't just participate in USENET...get rewarded for it!


How do you propose to transfer that reward to those who help you?

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
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
Sending mail encounters AuthenticationException (remote certificateis invalid ...) Afshar ASP .Net 2 04-10-2008 07:12 AM
a newbie encounters difficulties in using module Rose Perl Misc 4 02-17-2008 11:20 PM
Every program encounters a problem. xtasy8 General Computer Support 4 10-17-2006 02:00 AM
DVD Verdict reviews: NITRO DIGGERS, CRASH ENCOUNTERS, and more! DVD Verdict DVD Video 0 06-26-2004 09:01 AM



Advertisments