Skip to content Skip to sidebar Skip to footer

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 so

Solution 1:

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

Solution 2:

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)

Solution 3:

replace

document.form1.varAuctionTime.disabled = false

with

document.form1.varAuctionTime.disabled == false

Post a Comment for "Java Script Validation"