I have a dropdown list which runs the javascript function printResult
when the default selection is changed:
<form action="">
<select name="list" onChange="printResult();">
<option value="1"> Option 1</option>
<option value="2" selected> Option 2</option>
<option value="3"> Option 3</option>
</select>
</form>
I would like the form to submit the option that is selected as default when the page loads, as well as when another option is selected. All tutorials I can find only cover onchange
, rather than what I want.
Is this possible?
if you want to call a function on page load do this:
<body onload="printResult();">
<form action="">
<select name="list" onChange="printResult();">
<option value="1"> Option 1</option>
<option value="2" selected> Option 2</option>
<option value="3"> Option 3</option>
</select>
</form>
</body>
or in jquery you can postpone the load function anywhere in the page :
$(window).on("load",function(){ printResult(); })
or on document ready:
$(document).ready(function(){printResult();})