0

First of all, I'm using this function:

jQuery(document).on('propertychange change click keyup input paste', 'input[name="wager_id_111"]', function(){
        var thisValue = jQuery(this).val();
        var amountReal = jQuery('.amount_visible');

        if ( thisValue != '' ){
            var amount_in_btc = thisValue / 1000;
            amount_in_btc = amount_in_btc.toFixed(5);
            amount_in_btc = parseFloat(amount_in_btc);
            amountReal.show(1, function(){
                amountReal.find('span').html('= ' + amount_in_btc);
            });
        } else {
            amountReal.hide();
        }
    });

and it works when user types amount it the input. The problem is, when input value is being changed via code, so I can't detect it was changed. Becouse there is buttons how much amount add to input (like 1, 10, 50, 100) and when users selects one of those, input value is being changed jQuery('input[name="wager_id_111"]').val(newVal); but as I said the function I showed below can't catch this. What the option would be to make it work?

Fiddle:

fiddle link

2
  • question of clarification: when you press a button (1, 10, 50, 100) you programmatically change the value of the input, and its not currently picking up that value change so you're asking if there's a way for your function to pick it up? Commented Oct 22, 2015 at 20:32
  • @indubitablee yes, this is exactly what I'm looking for. To modify my function as well. Commented Oct 22, 2015 at 20:35

2 Answers 2

2

you can add this line of code: $('input[name="wager_id_111"]').trigger('change'); to your .click() function

demo: http://jsfiddle.net/et3gsf9w/1/

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

Comments

1

The solution is to place the code that operates the input value into a function, and call it two times, one when the event is raised and the other one via code.

2 Comments

this is the worst option I could choose so I keep it in the last place, I'm looking the option how to deal with one function. And by the way - did you checked if it works? Becouse I think it will fail (I'm talking about receiving input value after changing it with .val() method)
You just send it to the function as parameter or you just can access to the value becouse you already know the id.

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.