473,386 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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!=8) {
alert("Please enter a valid 8 digit telephone number this Team
member")
thisdoc.Role.focus();
return;
}
if(ContactNo.length!=8) {
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()

Jul 23 '05 #1
9 1443
ef*****@epitome.com.sg 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
Jul 23 '05 #2
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

:)

<ef*****@epitome.com.sg> wrote in message
news:11**********************@g14g2000cwa.googlegr 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!=8) {
alert("Please enter a valid 8 digit telephone number this Team
member")
thisdoc.Role.focus();
return;
}
if(ContactNo.length!=8) {
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()

Jul 23 '05 #3
JRS: In article <11**********************@g14g2000cwa.googlegroups .com>,
dated Sun, 27 Feb 2005 02:33:58, seen in news:comp.lang.javascript,
ef*****@epitome.com.sg posted :
if(ContactNo.length!=8) {
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.
Jul 23 '05 #4

Hi John

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?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #5
JRS: In article <42********@127.0.0.1>, dated Mon, 28 Feb 2005
11:21:25, seen in news:comp.lang.javascript, Effendi Baba
<ef*****@epitome.com.sg> 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.
Jul 23 '05 #6


Thanks John, that's very useful.

Regards

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #7
John

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?

Thank you once again.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #8
JRS: In article <42**********@127.0.0.1>, dated Wed, 2 Mar 2005
04:04:58, seen in news:comp.lang.javascript, Effendi Baba
<ef*****@epitome.com.sg> 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.
Jul 23 '05 #9

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.


John, don't get me wrong. What you have give me works perfectly for the
telephone number check. I am just trying to get a resource when I can
run similar test to check for example that a string don't contain
punctuation marks etc. In any case, what's you've give me is very
useful. It was excellent.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: lawrence | last post by:
Suppose I create dynamic web pages with 3 functions (which call other functions to make everything happen, but these 3 you might think of as being the top layer): registerSessions();...
72
by: Stephen Poley | last post by:
I have quite often (as have probably many of you) come across HTML forms with irritating bits of Javascript attached. The last straw on this particular camel's back was a large form I was asked to...
3
by: Skippytpe | last post by:
Does anyone have an idea why the form validation in the following page wouldn't be working? I had been using XHTML 1.0 transitional which allowed me to use the form attribute 'name.' I could then...
2
by: Shone | last post by:
I would like to perform a 2-pass XML reading from a stream. Once using the Validating reader, just to confirm the validity against the schema, and next time to do a reading to extract the data....
2
by: Martyn Fewtrell | last post by:
Dear All I have a Windows 2003 Server with IIS6 where the validation controls on ASP.Net pages no longer work. I believe it to be specific to the server as if I create an ASP.Net page on the...
9
by: AFN | last post by:
I was just dropped into someone else's code (isn't that always so fun?). I can't figure out why a custom validation control's server event function is executing. There is nothing (that I see)...
8
by: Richard Maher | last post by:
Hi, I am in a mouseup event for button A and I'd like to disable=false button B before starting some work. Is there anyway that an event for button B can then fire before my event processing for...
0
by: pauland80 | last post by:
<snip> <snip> Late thanks for your both answers! (Please excuse me for that) The problem was a bug in the device firmware. But before finding this, I dugg lightly in the pyserial source...
3
by: Tom | last post by:
Basically I have a page that I load with 10 input fields. If users have JS enabled I want to hide 5 of these fields so as to reduce clutter. If the user needs these extra fields an "Add" button can...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.