Placeholder in Javascript - DOM

0

If we want to report the information that a input field must have in HTML , for example, the attribute "placeholder"

should be used

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php">
  <input type="text" name="fname" id="fname" placeholder="First name"><br>
  <input type="text" name="lname" if="lname" placeholder="Last name"><br>
  <input type="submit" value="Submit">
</form>
</body>
</html>

How could "placeholder" be used for Javascript code? Taking the value of id , document.getElementById("fname")

    
asked by omaza1990 04.06.2017 в 14:15
source

1 answer

1

document.getElementsByName('fname')[0].placeholder='Tu nuevo placeholder';
document.getElementById('lname').placeholder='Tu placeholder 2';
<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php">
  <input type="text" name="fname" id="fname"><br>
  <input type="text" name="lname" id="lname"><br>
  <input type="submit" value="Submit">
</form>
</body>
</html>

And you can also by the Id

document.getElementById('fname').placeholder='Tu placeholder';
    
answered by 04.06.2017 / 14:29
source