user706499
user706499

Reputation: 49

Multiplying in Javascript

I need to multiply priceMonthly by 30, How can I do that in this "if" function? I am using it to echo the entered number live , but I need that number to multiply by 30. Dose someone have over ideas, or can someone guide me why its not working ?

function keyup_fill(ele, ele_place) {
    $(ele).on("keyup", function(event) {

        if ( $(ele).attr("name") === "priceMonthly" ) {
            if (!$.isNumeric($(ele).val())) {
                return ($(ele).val()*30); //not working
            }
        }

      var newText = event.target.value ;
        $(ele_place).html(newText); 
    });
}


keyup_fill("#priceMonthly", "#priceMonthly-place");

Upvotes: 0

Views: 312

Answers (1)

mgarcia
mgarcia

Reputation: 6325

If what you want is to show in #priceMonthly-place the result of multiplying by 30 the value entered in #priceMonthly you can do this with the code (note that I'm assuming that both ids represent input elements):

function keyup_fill(ele, ele_place) {
    $(ele).on("keyup", function(event) {
        // I'm assuming that `ele` is an input.
        var value = $(this).val();
        if ($.isNumeric(value)) {
            // I'm assuming that ele_place is an input.
            $(ele_place).val(value * 30);
        }
    });
}

keyup_fill("#priceMonthly", "#priceMonthly-place");

Upvotes: 1

Related Questions