Link to home
Create AccountLog in
Avatar of eltagi
eltagiFlag for Qatar

asked on

Dropdown SelectedIndexChanged fires the onSubmit script specified in the form tag

Since upgrading from .NET 1.1 to 4.0 I have a problem with a form.

The form has some dropdowns with AutoPostBack=true because they have some SelectedIndexChanged handlers that need to fire to populate other dropdowns, etc.

But now, when a new value is selected in the dropdown, it fires the onSubmit script specified in the form tag:

<form id="Form1" method="post" runat="server" onsubmit="return submitMe(this) ;">

Where before, that would only fire when the button control was clicked:

<input id="submit1" class="button" type="submit" value="Save" name="submit1">

What's the best way to rectify this?
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of eltagi

ASKER

Hello mplungjan, and thanks for your reply.

The submitMe validates some inputs and save the data to the DB.
-------------------

I removed the onsubmit from the form tag and added onclick to the submit button as you suggested:

<input id="submit1" class="button" type="submit" value="Save" name="submit1"
onClick="return submitMe(this.form)">

but onclick event of the submit button is not firing.
That is surprising. But then it could be down to the ASP which I do not know anything about.

Can you test for the window.event in the submitMe to see what fired the submit?

<form "return submitMe(this,event)"

function submitMe(theForm,e) {
  var evt = e?e:window.event;
  var tgt = evt.target?evt.target:evt.srcElement;
  if (tgt && tgt.id !="submit1") return;
.
.
.
Avatar of eltagi

ASKER

mplungjan, Just a minute . Before your suggestion I tried it like this:

<input id="submit1" class="button" type="submit" value="Save" name="submit1"
onClick="return submitMe(this)">

let me try yours:

<input id="submit1" class="button" type="submit" value="Save" name="submit1"
onClick="return submitMe(this.form)">

i.e.

submitMe(this.form)

instead of

submitMe(this)
Avatar of eltagi

ASKER

Good news mplungjan, it is working ...


Thanks so much mplungjan, I will give full marks for your answer.
Apologies for not highlighting the .form in my answer
Avatar of eltagi

ASKER

Thanks.

Any idea why this happens after upgrading from vs2003 to vs2010?
No, sorry. Possibly they decided it was more clever to actually submit the form