Search code examples
javascriptjqueryinputliveonkeyup

Change div on input (live & pass variable)


I want a div that shows your input, but for example * 2.

I also want it to happen as you type. So it has to be 'live'.

I found a lot of 'on keyup' jquery functions but I need to change the 'variable' that is typed in the input field.

So for example:

<input id="input" /> (types 4)

<div class="showinputhere"> (shows 8) </div>

How do I do this, it has to happen immediately when you type.


Solution

  • Use this

    $(document).ready(function()
        $('input').keyup(function(){
            $('.showinputhere').html(parseInt($(this).val(),10) *2);
        });
    });
    

    JSFiddle -> http://jsfiddle.net/gLExt/