473,379 Members | 1,201 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

innerHTML sometimes reverts to previous value after function return


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
sa****@unx.sas.com SAS Campus Drive are mine and not necessarily
(919) 677-8000 Cary, NC 27513, USA those of SAS Institute.
Jun 1 '06 #1
2 2487

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.

Jun 1 '06 #2
"web.dev" <we********@gmail.com> wrote in message
news:11**********************@h76g2000cwa.googlegr oups.com...
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.


Thanks! I had confused the button element with the input element with
type="button".
Jun 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: lendle | last post by:
I have defined onclick event handler within the innerHTML property as following: var testButton1=oWin.document.createElement("LABEL"); testButton1.innerHTML="<input type='button' value='xx'...
9
by: Hallvard B Furuseth | last post by:
Why does the FAQ (Q 4.15) recommend innerHTML when so many here say one should use createElement(), replaceChild() etc? Also, why does the "Alternative DynWrite function" at...
6
by: fmdevelopertim | last post by:
New to AJAX so sorry if this is simple. Have a page that gives the user a list to select a brand. Based on the brand selected it shows a list of sizes available using the following code: ...
4
by: tcole6 | last post by:
My problem appears to be Firefox specific. I have a hyperlink that loads a new window. This window contains hyperlinks that call javascript functions in the parent window and then closes the...
17
by: PJ | last post by:
Greetings... I have stumbled upon a small problem. I use Ajax to retrieve part of a page I need to update. I update a DIV element with the HTML contents I get from another page. It works...
7
by: bobd314 | last post by:
Currently, I am having a problem replacing the value of a input box with something else using the innerHTML thing. Right now I have something going <script type="text/javascript"><!-- function...
7
by: Lorenzo Bettini | last post by:
Hi on the same page I set the innerHTML property of an element to something like my_string + "<br />" then when I try to remove my_string + "<br />" from the innerHTML it fails since the...
9
by: martymix | last post by:
simple question: I have a simple <dt>test text</dt> I get the innerHTML of that dt, and I try and append some text to it like so: dt = document.getElementsByTagName('dt') var text =...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.