Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

disabling buttons in JavaScript

 
Richard Olmstead
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64685
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Richard Olmstead
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64685
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64685
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your latest advice worked, Bear!

Many thanks.

Regards,
Rick
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic