473,399 Members | 3,888 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,399 software developers and data experts.

Problem with .innerHTML, AJAX and Firefox

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 child window. The function that is called contains an
XMLHttpRequest.

My problem is that everything happens as it should, the innerHTML is
changed by the results of the XMLHttpRequest and the child window
closes. The problem is this, in Firefox, the screen doesn't display the
change until I click anywhere on the parent window. Then the element(s)
update with their new values. In IE and Opera it works on the fly.

I've tried things like setting focus on the parent window and even
setting focus in an element inside a form. These focus calls happen (I
can see the cursor appear in the form element) but it still doesn't
update the screen until I click on it.

This is in an intranet application so I can't provide a hyperlink to
the page. If anyone knows what I'm talking about that would be awesome.
If not I can probably cut and paste the relevant code although it might
be quite a bit.

Again, this only happens in Firefox and appears to be some sort of
refresh/focus problem. Thanks for your help.

Jun 30 '06 #1
4 5096
For the record books here's the javascript:

/*
*This function is in the parent window and is called by the child
window...
*/
function getSelectedPriceBreak(item, quantity) {
if (document.getElementById(item)) {
document.getElementById(item).value = quantity;
this.window.focus();
checkPrice(item);
document.getElementById(item).focus();
}
}

/*
*This method is the parent window and is called by either the method
above or
*via onBlur() events by various form components. When called by
onBlur() on a form
* component the update is immediate in all browsers. It's only when
called by
* getSelectedPriceBreak (via a child window) that the update doesn't
appear in Firefox
* until the user clicks anywhere in the parent window.
*/
function checkPrice(param) {
if (document.getElementById(param)) {
request = getRequest(updatePrice);
var value = document.getElementById(param).value;
request.open("GET", "/portal/servlet/update.do?item=" + param +
"&qty=" + value, true);
request.send(null);
}
else {
alert("Can't find the element.");
}
}

/*
*This method is called onreadystatechanged. There are no execution
problems
*whatsoever, just view issues in Firefox.
*/
function updatePrice() {
if (request.readyState == 4) {
if (request.status == 200) {
var xmldoc = request.responseXML.documentElement;
var item =
xmldoc.getElementsByTagName('item')[0].firstChild.data;
var quantity =
xmldoc.getElementsByTagName('quantity')[0].firstChild.data;
var baseQty =
xmldoc.getElementsByTagName('baseQty')[0].firstChild.data;
var price =
xmldoc.getElementsByTagName('price')[0].firstChild.data;
var basePrice =
xmldoc.getElementsByTagName('basePrice')[0].firstChild.data;
var unit =
xmldoc.getElementsByTagName('unit')[0].firstChild.data;
var baseUnit =
xmldoc.getElementsByTagName('baseUnit')[0].firstChild.data;
var um =
xmldoc.getElementsByTagName('um_description')[0].firstChild.data;
var sales =
xmldoc.getElementsByTagName('sales')[0].firstChild.data;
var total =
xmldoc.getElementsByTagName('total')[0].firstChild.data;
if (document.getElementById(item))
document.getElementById(item).value = quantity;
if (document.getElementById('' + item + '_qty'))
document.getElementById('' + item + '_qty').value =
quantity;
if (document.getElementById('' + item + '_baseQty'))
document.getElementById('' + item + '_baseQty').innerHTML =
baseQty;
if (document.getElementById('' + item + '_price'))
document.getElementById('' + item + '_price').innerHTML =
price;
if (document.getElementById('' + item + '_basePrice'))
document.getElementById('' + item + '_basePrice').innerHTML
= price;
if (document.getElementById('' + item + '_unit'))
document.getElementById('' + item + '_unit').innerHTML =
unit;
if (document.getElementById('' + item + '_baseUnit'))
document.getElementById('' + item + '_baseUnit').innerHTML
= baseUnit;
if (document.getElementById('' + item + '_um'))
document.getElementById('' + item + '_um').innerHTML = um;
if (document.getElementById('' + item + '_sales'))
document.getElementById('' + item + '_sales').innerHTML =
sales;
if (document.getElementById('_total'))
document.getElementById('_total').innerHTML = total;
}
}
}

/*
*This function is in the parent window and opens the child window when
the
* appropriate hyperlink is clicked.
*/
function viewBreaks(item) {
window.open('/portal/webapps/customers/orders/breaks.jsp?item=' +
item, 'PriceBreaks',
'width=200,height=200,status=no,toolbar=no,scrollb ars=yes');
}

/*
*This is the onclick event registered with the hyperlink in the CHILD
window. It blurs
* itself (in an attempt to give focus back to the parent window first)
and then calls
* the getSelectedPriceBreak method in the parent window, then closes
itself.
*/
onclick="javascript:window.blur();
window.opener.getSelectedPriceBreak('33500-00002', '1080');
window.close(); return false

/*
*Just for kicks, this is the onblur event handler that works just fine
in the parent
* window for all browsers.
*/
onblur="javascript:checkPrice('33114-00050');"

Again, all the execution steps happen without error on all browsers.
Only in Firefox
the component changes made in the updatePrice method don't appear until
the user clicks in the window (IE, Opera and Netscape all work
normally). Problem is I used AJAX so the user would get instantaneous
feedback.

Thanks again.

Jun 30 '06 #2
tc****@gmail.com wrote:
For the record books here's the javascript: [...]
if (document.getElementById('' + item + '_qty'))
document.getElementById('' + item + '_qty').value =
quantity;
if (document.getElementById('' + item + '_baseQty'))
document.getElementById('' + item + '_baseQty').innerHTML =
baseQty;


What are you trying to change using innerHTML? Changing the value
attribute in Firefox will not modify the element's innerHTML. Use DOM
methods only, not innerHTML.

innerHTML is a proprietary Microsoft invention that has been widely
copied. Since there is no public standard, implementations differ[1].
One of the most obvious is that IE updates the element's innerHTML
property to reflect its current HTML, Firefox tends to keep the
innerHTML property as it was when the page loaded - essentially a 'view
source'.

I hope that helps.

1. A public standard would not guarantee consistent implementation, but
it would probably help.

--
Rob
Jun 30 '06 #3


tc****@gmail.com wrote:

Again, all the execution steps happen without error on all browsers.
Only in Firefox
the component changes made in the updatePrice method don't appear until
the user clicks in the window (IE, Opera and Netscape all work
normally).


Netscape works fine and Firefox does not? Which versions of Netscape
respectively Firefox have you tried that?
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 1 '06 #4
Sometimes I wonder where my brain is...

I was setting focus to the window and component but it wasn't updating
because the event was fired by onblur. I simply called
document.getElementById('id').blur() and all is updating fine.

Thanks.

Jul 5 '06 #5

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

Similar topics

2
by: sveinn | last post by:
Hi all, I've read through this group searching for an answear about this problem. Few have come close but not quite what I need. My problem is this: I'm using Ajax to fetch a new table with...
2
by: jfaulky | last post by:
Hi all, I have a simply AJAX function that I pass a URL and it returns its contents to a <DIV id="mydivname"> area of my screen. All works fine when I manually enter:...
2
by: K. | last post by:
Hello! I have the following problem. I have form div which is replaced by ajax event. Unofrtunately all the ajax inputs are null after posting the form (method="post") in Firefox, but on...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
5
by: pjdeklerk | last post by:
I have a web page which has javascript which uses the innerHTML property of a <TD> object to replace that table cell's contents. The contents are of the form...
7
by: RaefKandeel | last post by:
Hi all, this is my first post. I have a little ajax assignment that works fine on mozilla firefox 2.0, but doesn't work at all on Internet Explorer 7. Apparently it has to do with the line where...
3
rizwan6feb
by: rizwan6feb | last post by:
Hi experts! Recently i was working on "Form Validation Using Ajax". My form validation was creating problem, when a user changes focus too quickly. I had a post related to this, but was unable to...
1
by: Robin | last post by:
Martin wrote: .... You appear to be putting the responseText into DIV 'htmlText' then 'hiddenDiv'. You therefore have two DIVs with id 'divslct4' (not legal as IDs are supposed to be...
8
by: cyqotiq | last post by:
First, let me state that this is not necessarily a Firefox problem, as I haven't fully tested in IE just yet. Second, let me state that this is not the typical "getElementById not working Firefox"...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.