ONKEYUP opening function TOGETHER with ONCLICK

Asked

Viewed 47 times

0

I have an input text.

When Clicking on INPUT "category" opens the #result field, simple! When you type more than 1 character open the #result field, simple!

WHAT I WANT: That the two functions work together! I MEAN when you click by "onclick" or when you do a search "onkeyup"

<!-- ONKEYUP -->
$("#categoria").keyup(function(){

var query = $(this).val();

if($("#categoria").val().length > 0){

$("#resultado").show();//

)};

<!-- ONCLICK-->
$("#categoria").click(function(){


 $("#resultado").show();//
)};
  • Even so I edited to facilitate! Please remove this duplicate

  • Alh, but what you want to do is no longer what is done? Both events display the element with id resultado, what you meant by "working together"?

  • Remove the callback from keyup and declare it as a function: function eventoComum(){var query = $(this).val(); $("#resultado").toggle();} .Then pass the function to the handlers keyup and click so that the two share the same callback: $("#categoria").keyup(eventoComum); and $("#categoria").click(eventoComum).

  • If you click musta to div, or the keyup shows the div, because you don’t just do an event using . Focus(), so it would suit both things... the functionality you want is half incoherent...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.