By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,401 Members | 793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,401 IT Pros & Developers. It's quick & easy.

javascript __doPostBack() problem in IE

P: 3
Hello, I have an address form which has a select box with countries and another select box with provinces.

When I select a certain country I cause a postback by using javascript __doPostBack function. I also have a submit button.

It works perfectly in both firefox and IE when I click on selectbox and select a country - it posts back and then on page load I populate the provinces based on the country just selected.

- EXCEPT: when I click on the select in IE, then select a country BUT I don't click on it, I hit enter to select that country.

This causes IE to actually submit the form as if I had clicked the submit button, which is NOT what I want.

Now if i change the type of the button to "button" instead of "submit", it doesn't behave that way, but then the user can't submit by hitting Enter.

I'm sure someone has come across this problem.
Is there a workaround for this?
Any idea on how to fix this?
Apr 26 '07 #1
Share this Question
Share on Google+
3 Replies


Frinavale
Expert Mod 5K+
P: 9,731
Hello, I have an address form which has a select box with countries and another select box with provinces.

When I select a certain country I cause a postback by using javascript __doPostBack function. I also have a submit button.

It works perfectly in both firefox and IE when I click on selectbox and select a country - it posts back and then on page load I populate the provinces based on the country just selected.

- EXCEPT: when I click on the select in IE, then select a country BUT I don't click on it, I hit enter to select that country.

This causes IE to actually submit the form as if I had clicked the submit button, which is NOT what I want.

Now if i change the type of the button to "button" instead of "submit", it doesn't behave that way, but then the user can't submit by hitting Enter.

I'm sure someone has come across this problem.
Is there a workaround for this?
Any idea on how to fix this?

Hi Rizzy!

You could use a little bit of JavaScript to trap the event when the enter key is pressed

-Frinny
Apr 27 '07 #2

P: 3
thanks Frinny,

but it's too late by the time it gets to catchKeyPress(). The postback happens before this. And I forgot mention that this only happens with select boxes that have __doPostBack(eventarget,eventarg) tied to their onchange event. Maybe IE mixes up the eventtarget somehow or something. I don't know how i'm gonna fix this.
Apr 30 '07 #3

Frinavale
Expert Mod 5K+
P: 9,731
thanks Frinny,

but it's too late by the time it gets to catchKeyPress(). The postback happens before this. And I forgot mention that this only happens with select boxes that have __doPostBack(eventarget,eventarg) tied to their onchange event. Maybe IE mixes up the eventtarget somehow or something. I don't know how i'm gonna fix this.
Hi Rizzy,

Maybe try using a button since this solution works. Then simply write some JavaScript function that catches the key up event for ever element on the form and checks which form element this event happened for. Compare this value to the select boxes and if it matches do not the submit since its going to post back anyways. Otherwise submit the form.

I hope this helps you!
Good luck,

-Frinny
May 1 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.