How to change input field using javascript onclick?

MaryAnn

Is it possible to change input field using javascript onclick?? My code:

<form>
 <input type="text" id="demo" value="John">
</form>
<button onclick="myFunction()">Click me!</button>  
<script>
  function myFunction() {
    document.getElementById("demo").value = "Hello World";
  }
</script>

it is successful to change the text, but it is failed to change input field value anyidea how to solve it??? Thank you very muchenter image description here

William Wang

To update the value field of the HTML as well, use setAttribute()

<form>
 <input type="text" id="demo" value="John">
</form>
<button onclick="myFunction()">Click me!</button>  
<script>
  function myFunction() {
    document.getElementById("demo").setAttribute("value", "Hello World");
  }
</script>

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Change Javascript Variables Using <input>

분류에서Dev

how to change the onclick attribute using jquery

분류에서Dev

Javascript input field not Working

분류에서Dev

javascript onsubmit change field value

분류에서Dev

Using event trigger how to pass the value to function on input change

분류에서Dev

How can I change uipanel dimensions by using user input?

분류에서Dev

Sterilizing javascript in <a onclick="sth" href =""> in user input

분류에서Dev

How to change CSS of child element <span> inside parent <div> element Using jQuery onclick event?

분류에서Dev

Using a PHP if statement to produce a hidden input field

분류에서Dev

Open accordion using onfocus on input field

분류에서Dev

How to move a field left and right without user input, using ints in xna

분류에서Dev

Need help using Javascript to insert an onclick event

분류에서Dev

How to display short date in input field?

분류에서Dev

How do I change Button Text color onclick event(asp.net, C#)using Css file?

분류에서Dev

jQuery setting input using val() and activating change()

분류에서Dev

Is it possible to be able to change an array using the input of a user?

분류에서Dev

change JSON structure using javascript

분류에서Dev

How to change the default value of stage field

분류에서Dev

How to return the onclick function is result to href in javascript?

분류에서Dev

How to put a button inside of a text entry field in a form on a website using javascript, css, html

분류에서Dev

How to Input a Discount Price in Javascript?

분류에서Dev

How to change html input multiple value

분류에서Dev

change volume of video using range input using jquery

분류에서Dev

How to change the input tag's response to addEventListener('change')?

분류에서Dev

Validate Multiple Input fields using JavaScript

분류에서Dev

dynamic calculation of input fields using php javascript

분류에서Dev

javascript : how to change "this" scope on an event

분류에서Dev

onclick event hide and show 2 forms using javascript

분류에서Dev

Get user input from input field in react similar to getElementById in react native using props

Related 관련 기사

  1. 1

    Change Javascript Variables Using <input>

  2. 2

    how to change the onclick attribute using jquery

  3. 3

    Javascript input field not Working

  4. 4

    javascript onsubmit change field value

  5. 5

    Using event trigger how to pass the value to function on input change

  6. 6

    How can I change uipanel dimensions by using user input?

  7. 7

    Sterilizing javascript in <a onclick="sth" href =""> in user input

  8. 8

    How to change CSS of child element <span> inside parent <div> element Using jQuery onclick event?

  9. 9

    Using a PHP if statement to produce a hidden input field

  10. 10

    Open accordion using onfocus on input field

  11. 11

    How to move a field left and right without user input, using ints in xna

  12. 12

    Need help using Javascript to insert an onclick event

  13. 13

    How to display short date in input field?

  14. 14

    How do I change Button Text color onclick event(asp.net, C#)using Css file?

  15. 15

    jQuery setting input using val() and activating change()

  16. 16

    Is it possible to be able to change an array using the input of a user?

  17. 17

    change JSON structure using javascript

  18. 18

    How to change the default value of stage field

  19. 19

    How to return the onclick function is result to href in javascript?

  20. 20

    How to put a button inside of a text entry field in a form on a website using javascript, css, html

  21. 21

    How to Input a Discount Price in Javascript?

  22. 22

    How to change html input multiple value

  23. 23

    change volume of video using range input using jquery

  24. 24

    How to change the input tag's response to addEventListener('change')?

  25. 25

    Validate Multiple Input fields using JavaScript

  26. 26

    dynamic calculation of input fields using php javascript

  27. 27

    javascript : how to change "this" scope on an event

  28. 28

    onclick event hide and show 2 forms using javascript

  29. 29

    Get user input from input field in react similar to getElementById in react native using props

뜨겁다태그

보관