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.
-
What have you tried .. The concept is the same as using name, a simple trial and error answer...Brett Weber– Brett Weber2013-05-20 03:09:12 +00:00Commented May 20, 2013 at 3:09
Add a comment
|
1 Answer
document.getElementById('Id').value='new value';
https://developer.mozilla.org/en-US/docs/Web/API/document.getElementById
8 Comments
nnnnnn
In my opinion just the fact that w3schools charges money to issue certificates that no employers are likely to recognise is reason enough to avoid them. Also the actual name "w3schools" seems like a cynical attempt to trick people into thinking they have some association with the w3c when they really don't, so that's another reason to steer clear.
Sk8erPeter
@Jayantha: the others are right, linking W3Schools as a reference is really bad. Please change your link to MDN (Mozilla's Developer Network): developer.mozilla.org/en-US/docs/Web/API/…. Thanks!
Jayantha Lal Sirisena
Ok got it, I will change. Thanks for the info.
sparsh610
Do i need to refresh it after set the value ... it didnt reflect on the UI
Jayantha Lal Sirisena
@sparsh610, no you don't need to refresh it should reflect immediately. If you refresh the browser it will be gone again.
|