Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Validating

Status
Not open for further replies.

Garabaldi

Technical User
Jan 16, 2002
61
0
0
CA
Hi folks,

I'm writing a typical html form that has two components which are mutally exclusive.

I have a radio button as the first line of my form which gives them two options (lets call them Option 1 and Option 2).

If they select Option 1 everytime they select an input field for the componets of Option 2 I would like an alert box to pop up stating "YOU CAN'T FILL THIS IN" (and visa versa)

I know you can do this in javascript. I've been wrestling with it for two days and I've got nothing to show for it. If anyone has any suggestiong I'd appreciate it.

Thanks,
 
You could write a function that, when a user clicks the radio buttons (onClick), is called and disables the input fields of option #2. That way, you'd never have to alert to the user "you can't fill this in".

You might use:
document.formname.inputvalue1.disabled=true;

...to disable the form element. I'm sure that would work for you. ;)
 
I usually go one step further and actually hide the elements that no longer form a usefull part of the interface. Why show the user a disabled control?
Code:
document.formname.inputvalue1.style.visibility='hidden';
 
dwarfthrower: Why show the user a disabled control?

A good question, and there's a good answer. A disabled control still imparts information.

Users have good pattern recognition -- all humans do. When we see a screen, whether the controls are enabled or disabled, we try to match it to known screens. So, it's a map for our brain in the application.

Furthermore, a screen with disabled controls tells us about the options on the screen. If you have a couple of radio buttons driving what further options are available, then you can tell right away what's active and what's not, without actually having to click anything.

Controls that disappear and reappear (especially if the layout of the screen changes with it) actually confuses more readers than it helps.

The only time I've seen a smart use of controls appearing and disappearing was when someone wanted to simulate the appearance of a tabbed window control. In that case, we expect the things we're looking at to disappear and be replaced by new things.

Maybe that helps for the next project... [smile]

Cheers,


[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top