0

In my game players have a balance and when they click the button it goes down by 5000, they start off with 20,000 when they reach 0, I want an alert to come up (i have that working) and the button to be disabled - I can't get that to work, can anyone shed some light please? All the functions are working perfectly btw I'm just trying to add in the disable button to the "Subtract" Function - Thanks!

here's the code I'm working with

<script type="text/javascript">
function subtract() {

var Balance = document.getElementById("Balance");
var Fee = parseInt(Balance.value) - 5000;
Balance.value = Fee;

if(Fee <= 0){
alert("To Continue Playing - Purchase More Coins at - LINK");
}
}
</script>


<button class="randombutton"  id="aaa" style="float:left;" onclick= "
 randomImg1(); 
 randomImg2(); 
 randomImg3(); 
 randomImg4(); 
 randomImg5(); 
 randomImg6(); 
 randomImg7(); 
 randomImg8();
 subtract();
 foo(this);"/>OPEN PACK</button>

1 Answer 1

3

To disable a form element with javascript you set the disabled property to true.

function subtract() {

    var Balance = document.getElementById("Balance");
    var Fee = parseInt(Balance.value) - 5000;
    Balance.value = Fee;

    if(Fee <= 0){
        // Get the element and then set the disabled property to true.
        document.getElementById('aaa').disabled = true;

        alert("To Continue Playing - Purchase More Coins at - LINK");
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you ! I would thumbs up your post if I could :)

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.