Kristian Rafteseth
Kristian Rafteseth

Reputation: 2032

Setting all the text-inputs on the page to one value

Example html:

<input type="text" name="nhdd9812"></input>
<input type="text" name="ndf4e"></input>
<input type="text" name="018y3"></input>
<input type="text" name="nsiohf8"></input>

How can I by javascript, set all text-inputs on the page to one value? (Without knowing their ids/names). Lets say "1" for examples sake.

Is this possible without a framework?

Upvotes: 0

Views: 30

Answers (1)

tymeJV
tymeJV

Reputation: 104785

You can do:

var inputs = document.querySelectorAll("input:text");
for (var i = 0; i < inputs.length; i++) { inputs[i].value = 1; }

Upvotes: 2

Related Questions