views:

480

answers:

2

I have a select field within a form:

<form id="myform">
<select id="value" onchange="javascript: document.myform.submit()">
    <option>....
</select>
</form>

After the form is submitted, it is impossible to use the 'back' button without resubmitting the form. However, if I use a regular 'submit' button, it is possible.

Is there a way you know of to get this behavior while still being able to use the javascript 'submit()'?

Accessibility is not a concern, having javascript enabled is required to use this site and that is the way the client wants it.

+2  A: 

Call a function instead.

<select id="value" onchange="sendForm()">

...script block...

function sendForm() {
    document.myform.submit()
}

Also, you never need to specify javascript: outside of an HREF tag.

Diodeus
Ok it goes back without re-sending the form, but the onchange="sendForm()" only works the first time...is there any way to re-set that?
W_P
I made a test with action="SomeNewPage.htm" and method="post" and iit works fine. What's your form action?
Diodeus
A: 

"onchange only works first time?"

Are you re-seelcting the same value? onchange only fires when there is a change. If you want to be able to reselect the same option, you need to use onblur.

Also you really should be using

document.getElementById("myform").submit();

epascarello