javascript __doPostBack() problem in IE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rizzy
    New Member
    • Apr 2007
    • 3

    javascript __doPostBack() problem in IE

    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?
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by rizzy
    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

    Comment

    • rizzy
      New Member
      • Apr 2007
      • 3

      #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(ev entarget,eventa rg) tied to their onchange event. Maybe IE mixes up the eventtarget somehow or something. I don't know how i'm gonna fix this.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by rizzy
        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(ev entarget,eventa rg) 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

        Comment

        Working...