1

I have seen two types of usage

var name = document.getElementById("username").value;

or

var name = document.getElementById("username").getAttribute("value");

Likewise for setAttribute also. I have a form where setAttribute works for one of the fields (it's a hidden field) and doesn't work for another field (not hidden) & I have to use

document.getElementById("username").value = "something"

to set the field

By doesn't work, I mean the field doesn't get set when I use setAttribute. It retains it's original value.

So what's the different between these 2 ways? Is there a rule on when one is supposed to use one way & when another?

user93353
  • 13,733
  • 8
  • 60
  • 122

0 Answers0