1

i wanted to disable a button when the page loads depending on the privilege level of the user. i already tried this code

if($previlage != 2)
{
    echo "<script>document.getElementById('US').setAttribute('disabled');</script>";
}

thanks in advance

2
  • 2
    You can do it in the HTML button with an if <button <?= ($previlage != 2) ? 'disabled' : ''; ?>> Commented Apr 14, 2015 at 3:44
  • Did any error appear in the console? Commented Apr 14, 2015 at 3:47

2 Answers 2

1

thy this

if($previlage != 2)
    echo "<script>document.getElementById('US').disabled = true;</script>";

make sure to print the JS after loading the button in DOM

Sign up to request clarification or add additional context in comments.

Comments

1

You can do this without any javascript or jquery code:

<button <?php echo $privillage != 2 ? "disabled='disabled'" : "" ?>> Button</button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.