Submitting form with JavaScript on selector change
I have added some code to automatically submit the form when a selector is changed:
<select name="template" id="templateselector" onchange='this.form.submit()'>
{{foreach $templates as $t}开发者_运维知识库}
<option value="{{$t}}"{{if $t==$template}} selected="selected"{{/if}}>{{$t}}</option>
{{/foreach}}
</select>
The bracket tags come from my template engine.
When the page is first loaded, and an entry of the select list is selected, the form submits. It then pre-selects the selected item in the list (selected="selected").
But when the item is pre-selected, the on submit action no longer works. Why is that?
Because you are "changing" from an item to the same item, which isn't a change.
精彩评论