Solved

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

Posted on 2004-08-17
4
172 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

860 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