JavaScript Get value from input with onclick value from input javascript,value from input field javascript,value

How can I get the value of input on click using vanilla javascript?

function getvalue() {
  console.log(this.val);
}
<input type="text" onclick="getvalue()" value="asdf"></input>
<input type="text" onclick="getvalue()" value="asdf2"></input>
<input type="text" onclick="getvalue()" value="asdf3"></input>
Answer:1

Use event.target.value inside your function call

When function gets called event object is passed to the function. event.target identifies which element called the function.

function getvalue() {
   console.log(event.target.value);
}
<input type="text" onclick="getvalue()" value="asdf"></input>
<input type="text" onclick="getvalue()" value="asdf2"></input>
<input type="text" onclick="getvalue()" value="asdf3"></input>
Answer:2

function getvalue(t) {
   console.log(t.value);
}
<input onclick="getvalue(this)" value="asdf"></input>
<input onclick="getvalue(this)" value="asdf2"></input>
Answer:3

Using vanilla javascript, you can do that like this:

function getValue(o) {
  console.log(o.value);
}
<input value="asdf" onclick="getValue(this)"></input>
<input value="asdf2" onclick="getValue(this)"></input>
<input value="asdf3" onclick="getValue(this)"></input>
Answer:4

I tried loading the events dynamically but did not get the output. I brought data using AJAX in the format of var datalist = "2015-09-22":{} $(".responsive-calendar").responsiveCalendar({ events:...

I tried loading the events dynamically but did not get the output. I brought data using AJAX in the format of var datalist = "2015-09-22":{} $(".responsive-calendar").responsiveCalendar({ events:...

I am trying to catch keycode for Dot and Delete but on different events. function validateSomething(eve) { var charCode = (eve.which) ? eve.which : eve.keyCode if (charCode == 46) console.log("...

I am trying to catch keycode for Dot and Delete but on different events. function validateSomething(eve) { var charCode = (eve.which) ? eve.which : eve.keyCode if (charCode == 46) console.log("...

I have an array that I would like to use to populate two different select box's but I'm seeing some weird behavior. Populating the first select works fine but when adding the same list to the second ...

I have an array that I would like to use to populate two different select box's but I'm seeing some weird behavior. Populating the first select works fine but when adding the same list to the second ...

  1. populate select box using javascript
  2. populate select box using ajax
  3. populate select box from database laravel
  4. populate select box jquery
  5. populate select box using jquery
  6. populate select box from database php
  7. populate select box from database using jquery
  8. populate select box using jquery ajax
  9. populate select box dynamically using jquery
  10. populate select box servicenow
  11. populate select box php
  12. populate select box javascript
  13. auto populate select box jquery
  14. jquery populate select box with json data
  15. auto populate select box javascript
  16. populate multi select box using jquery
  17. auto populate select box php
  18. codeigniter populate select box from database
  19. pre-populate select box jquery
  20. populate select option boxes using jquery

I have a lot of javascript plugins and libraries in my ASP.NET MVC project, that I want to convert to typescript. Questions: How to reference jQuery in ts files? I get this error below when I ...

I have a lot of javascript plugins and libraries in my ASP.NET MVC project, that I want to convert to typescript. Questions: How to reference jQuery in ts files? I get this error below when I ...