0

sorry for my eng//) how can i get count_val and use outside the function ?

function change_count(){
        var count_val = 0;
        $('input[name="count"]').keyup(function(){
            count_val = parseFloat($(this).val())||0;
            //console.log(count_val);
            //alert(count_val);
        });
        //alert(count_val);
        //console.log(count_val);

    }
    change_count();
    alert(count_val);
1
  • Your logic is strange, but you can just return the value you want Commented Feb 11, 2014 at 19:27

1 Answer 1

2

Your logic here is very flawed as the count_val value won't be changed until the keyup function has fired, but that will never happen until after the alert has been run, so the value will always show 0. Instead keep your logic within the keyup handler.

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.