wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes disabling buttons in JavaScript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "disabling buttons in JavaScript" Watch "disabling buttons in JavaScript" New topic
Author

disabling buttons in JavaScript

Richard Olmstead
Greenhorn

Joined: Jun 12, 2006
Posts: 5
Hello everyone,
In our application, managers log-in and see some Buttons, or regular users will log-in and see different buttons.
Without knowing who has logged in, I'd like to disable all buttons in this function:

function onCancel ()
{
document.forms[0].save_priority.disabled=true; //a manager's button
document.forms[0].save.disabled=true; //a user's button
}

The trouble is, if a user has logged on, the manager's button isn't displayed, and the first 'disable' gives me a script error.
Same thing if the manager logged on: the user's button doesn't display, and the second 'dsiable' gives an error.
How can check to see if a button is displayed, or absent?

Thank you,
Rick
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

What logic is being used to determine whether the button is displayed or not? Whatever it is, the same test should be made for including the JavaScript that controls it.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Richard Olmstead
Greenhorn

Joined: Jun 12, 2006
Posts: 5
Thank you, Bear.
I had hoped there was a way to check if a Button had a value of null, meaning it wasn't deployed. Your answer indicates this isn't possible.

Cheers,
Rick
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

No, I didn't say that.

But I don't think it's the best way to handle the situation. If you've got logic on the page that determines when to include the button, the best thing to do is to employ that same logic to omit or include the Javascript that controls that button.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

That said,

Originally posted by Richard Olmstead:
I had hoped there was a way to check if a Button had a value of null


Did you try something like:

Richard Olmstead
Greenhorn

Joined: Jun 12, 2006
Posts: 5
Your latest advice worked, Bear!

Many thanks.

Regards,
Rick
 
wood burning stoves
 
subject: disabling buttons in JavaScript