views:

18

answers:

1

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?

+1  A: 

Because you are "changing" from an item to the same item, which isn't a change.

David Dorward
I am not changing to the same item.I just have preselected an item and then select another one.
Workoholic
I've changed the code now to this: <script type="text/javascript"> $(document).ready(function () { $('#templateselector').change(function(){ $("#editor_form").submit(); alert("change event"); }); $("#templateselector option[value='{{$template}}']").attr('selected', 'selected'); }); </script>The problem remains, though. On the first load of the page, I can a change in the selector will submit the form. After that, the form is not submitted when I select another value. The alert is executed on every change, though!
Workoholic