Html select input select all options at once with JavaScript -


i have code

<!doctype html> <html> <body>  <select multiple>   <option value="volvo">volvo</option>   <option value="saab">saab</option>   <option value="opel">opel</option>   <option value="audi">audi</option> </select>  </body> </html>  

i want select option @ once javascript i've tried google , did not found

here 1 way it:

    function selectall()      {      	options = document.getelementsbytagname("option");      	for ( i=0; i<options.length; i++)      	{      		options[i].selected = "true";      	}      }
    <!doctype html>      <html>      <head>      </head>      <body>            <select multiple>      	<option value="volvo">volvo</option>      	<option value="saab">saab</option>      	<option value="opel">opel</option>      	<option value="audi">audi</option>      </select>            <button onclick="selectall();">select all</button>            </body>      </html> 


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -