0

I have following problem. After clicking on text I want to changing this text with input. After insert value in this input and press ENTER I want to returning input value.

I using this code but not worked after click enter :( :

$(document).ready(function() {

    $('.qty_new').click(function(){
        $(this).replaceWith("<input class='newVal' value='' />");
        return false;

        $('.newVal').keypress(function(e){
            var qty=$(this).val();
            var code =null;
            code = (e.keyCode ? e.keyCode : e.which);
            if (code == 13){
               alert('ratata');
            } 
        });
    });


    <span class='qty_new'>100</span>

Thanks in advance !

1 Answer 1

1

please see my fiddle - code works fine

http://jsfiddle.net/R6z9S/

just get rid off return false;


$(document).ready(function() {

    $(document).on('click','.qty_new',function(){
        $(this).replaceWith("<input class='newVal' value='' />");

        $('.newVal').keypress(function(e){
            var qty=$(this).val();
            var code =null;
            code = (e.keyCode ? e.keyCode : e.which);
            if(e.keyCode == 13) {
                alert('You pressed enter! '+qty);
            }
        });
    });
})
Sign up to request clarification or add additional context in comments.

Comments

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.