Solved

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

Posted on 2004-08-17
4
168 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

772 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

16 Experts available now in Live!

Get 1:1 Help Now