admin管理员组

文章数量:1405194

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.

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.

Share Improve this question asked Mar 6, 2009 at 14:18 user35288user35288 4
  • This sounds very browser-specific. What are you trying to acplish? Maybe there is a different approach that will help solve your problem. – jonstjohn Commented Mar 6, 2009 at 14:23
  • I say this again and again and again, be careful with onchange selects: stackoverflow./questions/580281/… – Dan Lew Commented Mar 6, 2009 at 14:24
  • It's for the iPhone, so IE doesn't matter. – user35288 Commented Mar 6, 2009 at 16:47
  • Ok it goes back without re-sending the form, but the onchange="function()" only works the first time...is there any way to re-set that? – user35288 Commented Mar 6, 2009 at 16:48
Add a ment  | 

2 Answers 2

Reset to default 2

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.

"onchange only works first time?"

Are you re-selecting 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();

本文标签: htmlonchangequotjavascript documentmyformsubmit()quot vs normal submitStack Overflow