views:

44

answers:

2

Assigning value to <li> tag using its id displays me error in IE 6 and IE7,,

Previously I was doing this:

document.getElementById("grandtotaldisplay").innerHTML = "TOTAL PRICE : $"+variable;

this throws me error in IE6 and IE7 as: alt text

Then I tried with jQuery library as suggested my others.. then also I was prompted with same error as displayed above.

here is how I used the jQuery .html() $("#grandtotaldisplay").html("TOTAL PRICE : $"+variable);

I am facing this issue in IE6 and IE7

How should I resolve it..please help.

Update below is the <li> tag where i need to place the required value using javascript

<li class="bannerprice" id="grandtotaldisplay">TOTAL PRICE : $0</li>
+1  A: 

you need to call that, only when the DOM is ready.

In other words, only when the page writes all tags, you can safely call them.

I would strongly recommend a frameworks to play with javascript, and writing plain javascript is now a pain and not fu at all :)

you can either call that javascript using the DOM Ready method, or append your javascript to the bottom of the page, instead the beginning.

<html>
  <head><title>my page</title></head>
  <body>
     <ul><li id="grandtotaldisplay">...</li></ul>

     <script type="text/javascript">

        $("#grandtotaldisplay").html("TOTAL PRICE : $"+variable);

     </script>
  </body>
</html>

or append to any place but wrap it up with the DOM Ready method

$(document).ready( function() {
    // safety call your DOM elements

    $("#grandtotaldisplay").html("TOTAL PRICE : $"+variable);

});
balexandre
A: 

This works: http://work.arounds.org/sandbox/41/run

This means that:

  1. You are not doing the call on window load/DOM ready
  2. You are dealing with iframes
  3. You made a typo somewhere

Try putting your code inside of window.onload = function(){ } or put a script element before the end body tag.

EDIT: Based on your duplicate question, if you're going to comment to my answer and say that it doesn't work, PROVIDE THE FULL SOURCE CODE or I'm not going to bother replying.

meder
i have a ajax call on select box onchange which makes this <li> populated, so is there any thing I should do for everytime the ajax function has been called?
OM The Eternity
providing full source code would be very clumsy I am updating question with the structure how does it goes..
OM The Eternity
One more thing DO NOT GET ANGRY.. Please :)
OM The Eternity
Your initial `document.getElementById` will not work if the `<li>` is made dynamically. You will need to bind it **AFTER** the ajax request is complete. In the `success:function(){}` do the `$('#el').html()`. **The first time you call `getElementById` if the LI is not created, it can't be referenced.**
meder
"providing full source code would be very clumsy I am updating question with the structure how does it goes" - you are wasting peoples time by not showing the actual code and context of the problem, which makes people guess. If you had provided a working replica, you would have got this solved the **first** time you posted the question.
meder
@Meder I have a simple Ajax request without the use of jQuery.. Updated part has the Ajax functions I have used.. See above
OM The Eternity
I already edited my answer and provided a live demo of your new code which works.
meder
Pls meder just have alook how every thing goes in it..
OM The Eternity
Can you replace the PHP snippets with the output of the PHP? Or make it fake.
meder
@meder I explained the output of the PHP code in the update pls seethe updated question
OM The Eternity
Why do you have `jQuery(document).ready( function() {` inside of another function? You shouldn't need that since the doc at that point should already be loaded.
meder
Please specify which function doesn't work. You have **two** functions that have the innerHTML/html statements.
meder
I was just testing it, pls tell me what should be done at that point as I am getting the error at that point only
OM The Eternity
Remove the document ready entirely. If you are creating the `li` dynamically, you need to reference it AFTER its been made, possibly in the same function.
meder