Thamus
Thamus

Reputation: 108

How to Disable a button using php and javascript

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

Upvotes: 1

Views: 52

Answers (2)

hamed
hamed

Reputation: 8033

You can do this without any javascript or jquery code:

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

Upvotes: 1

Abozanona
Abozanona

Reputation: 2295

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

Upvotes: 1

Related Questions