mevr
mevr

Reputation: 1125

Get the value of textbox after complete typing

Need to get the typed value after typing using JavaScript but function not working.

my code:

<input onkeyup= "myfunction()" type="number" name="textboxname" value="">

<script>
  
 function myfunction()
 {
   alert($(this).val());
 }

</script>

Upvotes: 1

Views: 672

Answers (2)

user15786743
user15786743

Reputation:

Give id to your input field and use $('#id').val() function

So your code should be

<input onkeyup="myfunction()" id="my_id" type="number" name="textboxname">

  <script>

    function myfunction() {
      alert($('#my_id').val());
    }

  </script>

Upvotes: 0

crg
crg

Reputation: 4557

You can pass to your function the value as a parameter

<input type="text" onkeyup="myfunction(this.value)">
<script>
function myfunction(value) {
    console.log(value)
}
</script>

Upvotes: 2

Related Questions