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 much
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] 삭제
몇 마디 만하겠습니다