innerHTML sometimes reverts to previous value after function return

Discussion in 'Javascript' started by Warren Sarle, Jun 1, 2006.

  1. Warren Sarle

    Warren Sarle Guest

    The page http://warrensarle.com/temp.html has three lines of text.

    The top one is a p element saying "Not in a form",
    which is not in a form.

    The middle one is a button element saying "Button in a form",
    which is in a form.

    The bottom one is a div element saying "Original text".

    Both the p element and the button element are given the same
    function as an onclick handler. This function assigns a string,
    "Testing innerHTML", to the innerHTML property of the div element,
    and then calls alert to say it is done.

    When the button is clicked, the text in the div changes to
    "Testing innerHTML" as expected. But after dismissing the
    alert box, the text in the div reverts to "Original text"
    when using Firefox or Opera. The text does not revert when
    using IE.

    Nor does the text revert when the p element is clicked in any
    of these browsers, unless you subsequently click the button,
    which causes "Testing innerHTML" to revert to "Original text"
    when using Firefox or Opera.

    Could someone please explain why the text reverts in some
    situations but not others?

    --

    Warren S. Sarle SAS Institute Inc. The opinions expressed here
    SAS Campus Drive are mine and not necessarily
    (919) 677-8000 Cary, NC 27513, USA those of SAS Institute.
    Warren Sarle, Jun 1, 2006
    #1
    1. Advertising

  2. Warren Sarle

    web.dev Guest

    Warren Sarle wrote:
    > The page http://warrensarle.com/temp.html has three lines of text.
    >
    > The top one is a p element saying "Not in a form",
    > which is not in a form.
    >
    > The middle one is a button element saying "Button in a form",
    > which is in a form.
    >
    > The bottom one is a div element saying "Original text".
    >
    > Both the p element and the button element are given the same
    > function as an onclick handler. This function assigns a string,
    > "Testing innerHTML", to the innerHTML property of the div element,
    > and then calls alert to say it is done.
    >
    > When the button is clicked, the text in the div changes to
    > "Testing innerHTML" as expected. But after dismissing the
    > alert box, the text in the div reverts to "Original text"
    > when using Firefox or Opera. The text does not revert when
    > using IE.
    >
    > Nor does the text revert when the p element is clicked in any
    > of these browsers, unless you subsequently click the button,
    > which causes "Testing innerHTML" to revert to "Original text"
    > when using Firefox or Opera.
    >
    > Could someone please explain why the text reverts in some
    > situations but not others?
    >


    If you check W3C, http://www.w3.org/TR/html4/interact/forms.html#h-17.5
    , by default, a button element by default is a submit. It appears FF
    and Opera honor this while IE does not. Some solutions:

    1. explicitly give the button a type
    2. handle the onsubmit event on the form so it does not submit the
    form.
    web.dev, Jun 1, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Saunders
    Replies:
    0
    Views:
    467
    John Saunders
    Aug 28, 2003
  2. plaztik via DotNetMonster.com

    ASP.Net Site Reverts to old version

    plaztik via DotNetMonster.com, May 4, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    412
    plaztik via DotNetMonster.com
    May 4, 2005
  3. DaBrain
    Replies:
    0
    Views:
    518
    DaBrain
    Nov 2, 2006
  4. paul reed

    Custom Control Width sometimes has a value...sometimes doesn't

    paul reed, Feb 17, 2004, in forum: ASP .Net Building Controls
    Replies:
    8
    Views:
    147
    Jeffrey Tan[MSFT]
    Feb 21, 2004
  5. Vic

    isinrole reverts to windowsprincipal?

    Vic, Nov 26, 2004, in forum: ASP .Net Security
    Replies:
    0
    Views:
    155
Loading...

Share This Page