-3

I have a question.

This is my button :

$balance = "3";
    <button type="submit" type=tex name="log" class="btn btn-primary">Ticket kaufen! Je mehr, desto mehr Chance habt ihr zu gewinnen!</button>

So, my problem is :

I want the button to become disabled if a user does not have enough money!

It is possible ? With Javascript or JQuery?

Sorry for my English! I hope you can help me!

Thanks

Edit :

I have tired this! :

    $balance = "3";
        <button type="submit" type=tex name="log" class="btn btn-primary">Ticket kaufen! Je mehr, desto mehr Chance habt ihr zu gewinnen!</button>

<script>
$('button').attr('1838383', $balance)

if ($('button').attr('193939') < COSTOFITEM) {
 $('button').hide()
}
</script>

But this doesn't work

2 Answers2

0

You can enable and disable the button using prop function of jquery.

You can create an id for your button. and disable it when $balance is not more than certain amount.

follow below code, this may get you what you want.

HTML:

<button id="submitButton" type="submit" type=tex name="log" class="btn btn-primary">Ticket kaufen! Je mehr, desto mehr Chance habt ihr zu gewinnen!</button>

JS :

if($balance < COST)
{
    $("#submitButton").prop("disabled",true);
}
else
{
    $("#submitButton").prop("disabled",false);
}

Hope this helps.

Ravi Shankar Bharti
  • 8,922
  • 5
  • 28
  • 52
0

I assume you are using bootstrap.

I assume you have an input field where the user can input a numeric value and when it becomes less the 3 dollars the button must be disable.

You need to add an event handler for the input field so that every time the user change the value a test must be done in order to enable or disable the button.

I try to explain with a snippet how to achive this result:

// when the document is loaded
$(function () {
  
  // every time the user change the input value
  $('#balance').on('input', function (e) {

    // set the property disabled of the button:
    //
    // 'button[name="log"]': means select a button with the
    // attribute name equal to the string log
    //
    //(+this.value < 3): means: translate the input value to
    // a number and test if it is less then 3
    //
    $('button[name="log"]').prop('disabled', (+this.value < 3));
  })
});
<!--
include the jquery and bootstrap 
-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-1.12.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>


<!-- I assume you have a form like...  -->
<form action="#">
    <div class="form-actions">
        <div class="input-group">
            <span class="input-group-addon">$</span>
            <input type="number" value="1000" class="form-control currency" id="balance"/>
        </div>
        <button type="submit" name="log" class="btn btn-primary">Ticket kaufen! Je mehr, desto mehr Chance habt ihr zu
            gewinnen!
        </button>
    </div>
</form>
gaetanoM
  • 41,594
  • 6
  • 42
  • 61
  • @TheBossInTheHouse In your PHP file you generate an HTML document. So, you need to add the "include the jquery and bootstrap " libraries into the head section of the generated HTML. In the body, instead, you need to insert "I assume you have a form like...". Finally, you need to add a script tag containing my javascript. – gaetanoM Aug 10 '16 at 22:17
  • 1
    Oke in Html work this! I try to put this in my php file! THANKS! – TheBoss InTheHouse Aug 10 '16 at 22:22
  • @TheBossInTheHouse Sorry, but I helped you on client side, now you need to do some little effort to write the server side. It's not so hard. Try googling the internet. And if you cannot find a solution try to ask another question, but this time the question must contain something of credible. – gaetanoM Aug 10 '16 at 22:36