473,401 Members | 2,146 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,401 software developers and data experts.

Javascript causes entire script to fail on web page

Any JavaScript folks want to take a shot at this? I have a larger
JavaScript that is doing form validation (I can provide it if needed).
But this particular piece of code causes the entire script to fail
(i.e., not execute) and allows the form to be submitted. As soon as I
remove it, the validation works fine.

if (employment_status.selectedIndex == 3 ||
employment_status.selectedIndex == 4 ||
employment_status.selectedIndex == 5 ||
employment_status.selectedIndex == 6) && (contract_end_date.value ==
"")
{
alert ("You must select an end date for the new hire if they are a
contractor or temporary employee in order to submit the New Hire
Form.")
employment_status.focus()
return false
}

Any help is appreciated as I've looked at this quite and bit nothing
jumps out. Please reply to the board so all can benefit.

Thanks,
Taz
Jul 23 '05 #1
5 1141
ta*@humanthinktank.com (Taz Lake) writes:

I assume "employment_status" is a declared variable that points to
a select element.
if (employment_status.selectedIndex == 3 || ^ parenthesis begin
employment_status.selectedIndex == 4 ||
employment_status.selectedIndex == 5 ||
employment_status.selectedIndex == 6) && (contract_end_date.value ==

parenthesis end-^ ^^-syntax error

This would have been caught by JSLint:
<URL: http://www.crockford.com/javascript/jslint.html >
It's error message is:
4) : error at character 39: Expected '{' and instead saw '&&'.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2
Lee
Taz Lake said:

Any JavaScript folks want to take a shot at this? I have a larger
JavaScript that is doing form validation (I can provide it if needed).
But this particular piece of code causes the entire script to fail
(i.e., not execute) and allows the form to be submitted. As soon as I
remove it, the validation works fine.

if (employment_status.selectedIndex == 3 ||
employment_status.selectedIndex == 4 ||
employment_status.selectedIndex == 5 ||
employment_status.selectedIndex == 6) && (contract_end_date.value ==
"")


Whatever browser you're using should be pointing out the syntax
error in that "if" statement.

The entire expression to be evaluated must be contained in parentheses.
You have two sets of parentheses joined by an && operator.
Add an outer pair, enclosing the entire expression.

Jul 23 '05 #3
Taz Lake wrote:
Any JavaScript folks want to take a shot at this? I have a larger
JavaScript that is doing form validation (I can provide it if needed).
But this particular piece of code causes the entire script to fail
(i.e., not execute) and allows the form to be submitted. As soon as I
remove it, the validation works fine.

if (employment_status.selectedIndex == 3 ||
employment_status.selectedIndex == 4 ||
employment_status.selectedIndex == 5 ||
employment_status.selectedIndex == 6) && (contract_end_date.value ==
"")
{
alert ("You must select an end date for the new hire if they are a
contractor or temporary employee in order to submit the New Hire
Form.")
employment_status.focus()
return false
}

Any help is appreciated as I've looked at this quite and bit nothing
jumps out. Please reply to the board so all can benefit.

Thanks,
Taz


employment_status= [valid reference here]
contract_end_date=[valid reference here]
// valid reference should include the document,
// the form, and the form control, for example:
// document["formName'].elements["selectName"]
if (employment_status.selectedIndex >2 &&
employment_status.selectedIndex<7 && !contract_end_date.value){

alert ("In order to submit the New Hire Form, you must select an end
date for the new hires if they are contractors or temporary employees.")
employment_status.focus();
return false;
}

Mick
Jul 23 '05 #4
Thanks to everyone for your assistance and suggestions. Apparently,
the most obvious errors are the most difficult to troubleshoot ;-)

I'm using Firebird instead of something like IE which will provide you
with JavaScript notifications in a pop-up window. I just typed
"javascript:" in the browser window and it reported the error (just
like Netscape, duh).

Thanks,
Taz
Jul 23 '05 #5
Taz Lake wrote:
I'm using Firebird instead of something like IE which will provide you
with JavaScript notifications in a pop-up window. I just typed
"javascript:" in the browser window and it reported the error (just
like Netscape, duh).


The Web Developer Extension will not only install helpful bookmarklets
accessible via a toolbar but also show an icon in that toolbar to
indicate if script errors/warnings have occurred. You can always
click the icon to display the JavaScript console. Available for
Mozilla/5.0 Seamonkey and Firefox.

<http://chrispederick.myacen.com/work/firefox/webdeveloper/download/>
HTH

PointedEars
Jul 23 '05 #6

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

Similar topics

1
by: Neil Sandow | last post by:
My site with servers located on the West Coast runs ads served by an adserver on the East Coast. A not infrequent problem occurs when a user on the West Coast tries to load a page but for whatever...
6
by: NotGiven | last post by:
I want to learn moer of what I saw in a recent example. They create a page that created new fields/element. It's not like they were hidden and they displayed them, they were not there, then the...
4
by: web_design | last post by:
I put this together from some other scripts I am using on a site. I'm trying to make a better email hiding script. It isn't working. Also, it causes Internet Explorer 6 SP2 to block the script...
3
by: Bill_W_Stephens | last post by:
I am modifying existing javascript code where the author appears to be passing an entire form to a javascript function called Require(). I want to add a new test: "is @BHFOR.value = blanks". ...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.