input - Change form value= attribute with Javascript -


i need simple javascript change value= attribute 2 when page loaded.

<input type="number" step="1" min="1" name="quantity" value="1" title="qty" class="input-text qty text"> 

addeventlistener('load', function() {     document.getelementsbyclassname('qty')[0].value = 2; }); 
  1. you first add event listener load event, runs after page's loaded
  2. within event listener's callback function, select element. in script, select class qty, since class seemed specific of three. should add id attribute input accurately select though.
  3. you first result, @ index [0], , set value 2.

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -