Solved

table.onclick isn't working for me for some reason

Posted on 2004-08-17
4
170 Views
Last Modified: 2012-05-05
i can't get table.onclick to work.  i've tried these things...
table.onclick       = function() {return FTB_Exit('FreeTextBox1');};
table.onclick= FTB_Exit('FreeTextBox1');
table.onclick= FTB_Exit;
table.onclick= "FTB_Exit('FreeTextBox1');

heres the function

function FTB_CreateTable(ftbName,cols,rows,width,widthUnit,align,cellpadding,cellspacing,border) {
      var editor = FTB_GetIFrame(ftbName);
      editor.focus();
      var sel = FTB_GetSelection(ftbName);
      var range = FTB_CreateRange(ftbName,sel);      
      
      var doc = editor.document;
      // create the table element
      var table = doc.createElement("table");
      

      // assign the given arguments
      table.style.width       = width + widthUnit;
      table.align                   = align;
      table.border             = border;
      table.cellspacing       = cellspacing;
      table.cellpadding       = cellpadding;
      table.id            = "table" + tableId++;
      table.onclick       = function() {return FTB_Exit('FreeTextBox1');};
      
      var tbody = doc.createElement("tbody");
      table.appendChild(tbody);      

      for (var i = 0; i < rows; ++i) {
            var tr = doc.createElement("tr");
            tbody.appendChild(tr);
            for (var j = 0; j < cols; ++j) {
                  var td = doc.createElement("td");
                  tr.appendChild(td);
                  // Mozilla likes to see something inside the cell.
                  if (!isIE) td.appendChild(doc.createElement("br"));
            }
      }
      
      if (isIE) {
            range.pasteHTML(table.outerHTML);
      } else {
            FTB_InsertNodeAtSelection(ftbName,table);
      }
      
      return true;
}

any ideas??  oh and it either doesn't do anything or gives some error.  html not implemented i think
0
Comment
Question by:tricos1
  • 3
4 Comments
 
LVL 15

Expert Comment

by:Colosseo
ID: 11821503
Hi

have you tried

table.onclick= "return FTB_Exit('FreeTextBox1')";

what does FTB_Exit do anyway?

Regards

Scott
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 11822003
i think the whole functio is wrong, here how I did mine a little while ago:


function makeOb(w,h,x,y,parent,txt,bgColor){
    var addTo=parent||document.getElementsByTagName("body").item(0);
    var obj=document.createElement('DIV');
    clip="";
    (h>-1)?clip="clip:rect(0px,"+w+"px,"+h+"px,0px);overflow:hidden;":'';
    obj.setAttribute("style","position:absolute;"+clip);
    obj.setAttribute("id","id"+windows.no);
    obj.innerHTML=txt+'\n';
    addTo.appendChild(obj);
    obj.style.position="absolute";
    obj.style.overflow="hidden";
    obj.style.left=x+"px";
    obj.style.top=y+"px";
      (w>-1)?obj.style.width=w+"px":'';
      (h>-1)?obj.style.height=h+"px":'';
      obj.style.clip="rect(0px,"+w+"px,"+h+"px,0px)";
      (bgColor)?obj.style.backgroundColor=bgColor:'';
    return document.getElementById("id"+windows.no++);

}


if you want to get it work use setAttributes like:

    obj.setAttribute("style","position:absolute;"+clip);
    obj.setAttribute("id","id"+windows.no);

and in the end define onclick event like this:

    document.getElementById("someid").onclick=.....




0
 
LVL 13

Expert Comment

by:davidlars99
ID: 11823073
if document.getElementById("someid").onclick=.....  won't work try other way

function eventAdder(objAttrib,handler,addFunction){
     
   if ((!document.all)&&(document.getElementById)){
       objAttrib.setAttribute(handler,addFunction);
   }    
   if ((document.all)&&(document.getElementById)){
       objAttrib[handler]=new Function(addFunction);
   }

}

and call this function from the inside FTB_CreateTable(...) (or in my example makeOb(...) ) like this:

eventAdder(objHTML,"onclick","dunebuggy()")




0
 
LVL 13

Accepted Solution

by:
davidlars99 earned 200 total points
ID: 11823485
if you want to pass argument in the function in the simple way try:

table.setAttribute("onclick", function(){  FTB_Exit('FreeTextBox1');  };

that's all
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Full Screen problem when auto scale IFRAME 2 61
Split in Javascript 5 30
Polygon I google maps 1 14
Jquery get each value 2 14
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now