0

Problem with this jquery:

$(".aaazzz").live("keyup", function(){

one = $("#amo").attr('value');
two = $("#ame").attr('value');
}

#amo is input field and #ame is select. The problem is that when I change something in #amo, it changes in real time but with select(#ame) it does not happen. Of course if I change #ame and then after change #amo it works, but how to get them both working?

Thank you in advance

1
  • Something like this? jsfiddle.net/7zwCc Commented Jun 5, 2013 at 16:33

1 Answer 1

3

You could use this:

$(document).on("keyup", ".aaazzz" ,function(){
    one = $("#amo").val();
    two = $("#ame").val();
});

The code uses .val() instead of .attr() and will correctly return the select value.

Here's a jsfiddle demonstrating it: http://jsfiddle.net/rxH8k/

UPDATE: If you want the variables to be defined when the keyup event is fired on .aaazzz and when #ame changes then you could use this code: http://jsfiddle.net/rxH8k/2/

$(document).on("keyup", ".aaazzz", function () {
    update();
});

$("#ame").on('change', function(){
    update();
});

function update(){
    one = $("#amo").val();
    two = $("#ame").val();
}
Sign up to request clarification or add additional context in comments.

3 Comments

Hmm, looks like problem is that with #ame it do not trigger to refresh jquery, is it possible to refresh it when I select values from dropdown ?
@MickeyOntegro - I've just updated my answer, it should answer your question.
Yes, looks like it is solved, I didn't did refresh, and didnt saw your answer before. Thank you !

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.