CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   object required? (http://www.codingforums.com/showthread.php?t=272258)

nikko50 09-04-2012 11:13 PM

object required?
 
Why do I get object required?

Code:

  <div id=layer1 style="visibility:hidden; position: absolute; top: 250; left: 20; width: 550; height: 100;  background-color: #FFFFFF; border: 2px dotted #6699FF; padding: 5px"></div>


<script>
function remove(removeId){

        alert(removeId);
};


var emptyDiv = "layer1";

var xx =" <span style='float:right'><a class='view' href='javascript:void(0)' onclick='remove("+emptyDiv+")'; return false;>Remove Report</a></span> ";

  document.getElementById(emptyDiv).style.visibility = 'visible';
  document.getElementById(emptyDiv).innerHTML = xx;
 

     
</script>


Old Pedant 09-05-2012 12:01 AM

I give up, why do you? I don't.

I do have to ask why you wrote
Code:

  .... onclick='remove("+emptyDiv+")'; ...
That's kind of meaningless.

It surely should have been
Code:

  .... onclick='remove(emptyDiv)'; ...

Old Pedant 09-05-2012 12:05 AM

As your code is written, you would be callling
Code:

remove(layer1)
There is no variable by that name, so when you end up doing
Code:

  alert(removeId)
you will either be doing the equivalent of alert(null) or, esp. in MSIE browsers, alert( the_object_with_the_id_of_layer1 ) (because MSIE treats IDs as object references if you don't override that meaning).

Lerura 09-05-2012 12:29 AM

Quote:

Originally Posted by Old Pedant (Post 1267000)
(because MSIE treats IDs as object references if you don't override that meaning).

This behaviour is as far as I can see implemented in FF 15 too

Old Pedant 09-05-2012 01:15 AM

Interesting. Didn't used to be. Wow. That's a big change.


All times are GMT +1. The time now is 11:45 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.