jeni
jeni

Reputation: 440

Java Script validation

Am validating a form for empty check.

All fields works fine.

I have a dropdown when i select some value from dropdown some fields will be disabled. onchanging the dropdown value someother fields will be disabled.

Now am struck in validating the fields which are getting disabled and enabled.

if((document.form1.varAuctionTime.disabled = false) && (document.form1.varAuctionTime.value == ""))   

I used above code but it is enabling the fields.

can anybody help me out.

Upvotes: 0

Views: 110

Answers (3)

Connell
Connell

Reputation: 14411

I upvoted Quentin's answer.

document.form1.varAuctionTime.disabled = false uses the assignment operator, which sets the value of disabled to false

document.form1.varAuctionTime.disabled == false will do a comparison and will return true if the value of disabled is false (or technically, if the value is 0 or an empty string)

document.form1.varAuctionTime.disabled === false will only return true if the value is false and not if it is 0 or an empty string. This is probably not required as AFAIK the disabled property will always return a boolean.

To give you a few alternatives that you may prefer; since the comparison operators return booleans, and the disabled property is a boolean anyway, you could just do the following

if(!document.form1.varAuctionTime.disabled && !document.form1.varAuctionTime.value)

Upvotes: 2

JSantos
JSantos

Reputation: 1708

replace

document.form1.varAuctionTime.disabled = false

with

document.form1.varAuctionTime.disabled == false

Upvotes: 0

Quentin
Quentin

Reputation: 943142

You are using = (assignment) where you want == (comparison)

Upvotes: 6

Related Questions