javascript - Return a value created in an event handler inside a function from the same function -


i have input box , go button. when user clicks go button want compare inserted value value. trying acquire input value inside function so

function getinput(){         var entry ='';         $('button.go').on('click',function(){             var entry = $(this).siblings('.input').val();             //return entry         })         return entry   } 

basically want return var entry has input value, compare values later in code

var input = getinput() // should have input value input > othervalue 

i call getinput inside document.ready()

you doing right . there scope related issues not helping expected result . suggestion define othervalue variable global , check inside function

function getinput(){            $('button.go').on('click',function(){        var entry = $(this).siblings('.input').val();              if(entry>othervalue) //your code          });      } 

i not sure why binding dynamic click event inside function . if there nothing else need here except part, wrap piece of code inside document.ready.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -