João Cunha
João Cunha

Reputation: 10307

Laravel PHP Jquery - TextBox updating Label

I have this textbox

{{ Form::text('horasT', $horasT, array('class'=>'input-block-level', 'placeholder'=>'0.00')) }}

I want to update a Label when the textbox value changes.

this is the label:

<label id="subTotal" name="subTotal">0</label>

My Jquery is this:

jQuery('#horasT').on('input', function (){
            var valT = $('#horasT').val();
            $('#subTotal').value = valT;
        });

It doesn't seem to work and I've tried a lot of things so far.

But for me this should work... What seems to be the problem? The label just sits in 0 no matter the value that is in the textbox

Upvotes: 2

Views: 2607

Answers (2)

Daniel Gasser
Daniel Gasser

Reputation: 5133

The event is change and a label has text not value

Possible other event to trigger on: "input change keyup keypress cut paste mouseup focus blur"

jQuery(document).on('change', '#horasT', function (){
            var valT = $(this).val();
            $('[name="subTotal"]').text(valT);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<label for="horasT" name="subTotal">0</label>
<input id="horasT" type="text">

Upvotes: 4

jumberi
jumberi

Reputation: 1

jQuery("#horasT").change(function() {
    $("#subTotal").text($(this).val());
});

Upvotes: -1

Related Questions