Solved

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

Posted on 2004-08-17
4
173 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

726 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