Mr.Chowdary
Mr.Chowdary

Reputation: 3417

How to set Field value using id in javascript?

I want to set an HTML field's value using JavaScript when onclick event is raised by clicking a button/hyperlink.. I Googled and found many articles using the name attribute, but I want to set the value using the field's id only.

Upvotes: 25

Views: 160966

Answers (1)

Jayantha Lal Sirisena
Jayantha Lal Sirisena

Reputation: 21376

document.getElementById('Id').value='new value';

https://developer.mozilla.org/en-US/docs/Web/API/document.getElementById

Upvotes: 51

Related Questions