Register FAQ/Rules Forum Spy Search Today's Posts Mark Forums Read

Welcome to the Mac Forums forums. Please read the FAQ if you have questions. Register to participate.

 
Go Back   Mac Forums > Special Interests > Web Design and Development
TouchArcade.com - iPhone Game Reviews and News

Reply
 
Thread Tools Search this Thread  
Old Aug 7, 2008, 07:17 PM   #1
CANEHDN
macrumors 6502a
 
CANEHDN's Avatar
 
Join Date: Dec 2005
Location: West Jordan, UT
AJAX expert needed.

Unfortunately I will not be able to provide links for this. I have a table that is displayed on the page. A user can press a button to added information to the database which in turn adds a new row to the table. I'm using AJAX to create the row without having to refresh. This works perfectly, finally.

Quote:
col4.innerHTML = "<a href='../actions/administrators_edit_form.php?adminID=" + adminID + "&keepThis=true&TB_iframe=true&modal=true' class='thickbox'><img src='../images/edit.gif' border='0'></a>&nbsp;<a href='../actions/administrators_delete.php?adminID=" + adminID + "&rw=" + rowCount + "&keepThis=true&TB_iframe=true&modal=true&width=250&height=75' class='thickbox'><img src='../images/cross.gif' border='0'></a>";
This is what one of the rows looks like. The class attribute works fine when the page loads but doesn't seem to work when I add the rows with AJAX. I use it to open a fancy popup box if the user clicks the image.

Here is the code that I use to create the row and the columns.

Quote:
var newRow = parent.document.getElementById("theTable").insertRow(rowCount);
newRow.style.backgroundColor=rowColor;

var col1 = newRow.insertCell(0);
col1.setAttribute("align", "center");
I hope you can understand this. Any help would be much appreciated.
__________________
:Macbook Pro 2.8GHz, 4GB RAM, 512MB VRAM
:20" Intel Dual Core 2.0GHz, 2GB RAM, 256MB VRAM
:1.25GHz G4 Mac Mini w/ 1GB RAM
:iPhone 3G

Last edited by CANEHDN : Aug 7, 2008 at 07:24 PM.
CANEHDN is offline   Reply With Quote
Old Aug 7, 2008, 09:12 PM   #2
Me1000
macrumors 68000
 
Me1000's Avatar
 
Join Date: Jul 2006
Quote:
Originally Posted by CANEHDN View Post
Unfortunately I will not be able to provide links for this. I have a table that is displayed on the page. A user can press a button to added information to the database which in turn adds a new row to the table. I'm using AJAX to create the row without having to refresh. This works perfectly, finally.



This is what one of the rows looks like. The class attribute works fine when the page loads but doesn't seem to work when I add the rows with AJAX. I use it to open a fancy popup box if the user clicks the image.

Here is the code that I use to create the row and the columns.



I hope you can understand this. Any help would be much appreciated.
I wont pretend to be a javascript expert, because I am not anywhere near close to one. However....

Let me make sure I understand your problem first. Thickbox isnt working on the new rows that are generated using the javascript? The class attribute is used by thickbox to figure out which links thickbox gets applied to. Am I right?

The problem could be a result of the code that thickbox uses to initialize itself when the page loads.

This is the function that is being called I am talking about...

Code:
//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domChunk){
  $(domChunk).click(function(){
  var t = this.title || this.name || null;
  var a = this.href || this.alt;
  var g = this.rel || false;
  tb_show(t,a,g);
  this.blur();
  return false;
  });
}

This is the actual call of the function, along with other calls...
Code:
$(document).ready(function(){   
  tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
  imgLoader = new Image();// preload image
  imgLoader.src = tb_pathToImage;
});
you might need to recall the tb_init() function after you generate the new row...

I think that would probably fix it, assuming I understood your problem correctly.
Me1000 is offline   Reply With Quote
Old Aug 7, 2008, 09:27 PM   #3
CANEHDN
Thread Starter
macrumors 6502a
 
CANEHDN's Avatar
 
Join Date: Dec 2005
Location: West Jordan, UT
You understand it exactly. I will try to call that that function again once I close the popup, tomorrow. Hopefully it works. Thanks for the help.
__________________
:Macbook Pro 2.8GHz, 4GB RAM, 512MB VRAM
:20" Intel Dual Core 2.0GHz, 2GB RAM, 256MB VRAM
:1.25GHz G4 Mac Mini w/ 1GB RAM
:iPhone 3G
CANEHDN is offline   Reply With Quote
Old Aug 7, 2008, 09:50 PM   #4
Me1000
macrumors 68000
 
Me1000's Avatar
 
Join Date: Jul 2006
Alright, then I would just copy this into your javascript, right after the new table row is created...

Code:
tb_init('a.thickbox, area.thickbox, input.thickbox');
Best of luck with this.
Me1000 is offline   Reply With Quote
Old Aug 7, 2008, 11:12 PM   #5
angelneo
macrumors 65816
 
angelneo's Avatar
 
Join Date: Jun 2004
Location: afk
Send a message via MSN to angelneo Send a message via Skype™ to angelneo
Erm...

Did you use setAttribute in this manner for your new row

Code:
newrow.setAttribute('class', 'thickbox');
Add this line in as well

Code:
newrow.className = 'thickbox';
newrow.setAttribute('class', 'thickbox');
Some browsers do not register style changes with setAttribute


For adding events such as onclick, use attachEvent for IE and addEventListener for the rest
__________________
This is good, isn't it?
angelneo is offline   Reply With Quote
Old Aug 8, 2008, 10:34 AM   #6
CANEHDN
Thread Starter
macrumors 6502a
 
CANEHDN's Avatar
 
Join Date: Dec 2005
Location: West Jordan, UT
I've both suggestions and still have the same issue. I even tried calling the function on an onClick event in the image and link. Any more suggestions? I'm sure this can be done.


I'm such a dingle berry. You were right. I forgot to add parent. I hate working on problems and once you come close to getting it, you forget the basic stuff. Since I've added this, it works.
Code:
parent.tb_init('a.thickbox, area.thickbox, input.thickbox');
Thanks a ton for you help. Here have a jolly rancher.
__________________
:Macbook Pro 2.8GHz, 4GB RAM, 512MB VRAM
:20" Intel Dual Core 2.0GHz, 2GB RAM, 256MB VRAM
:1.25GHz G4 Mac Mini w/ 1GB RAM
:iPhone 3G

Last edited by CANEHDN : Aug 8, 2008 at 12:10 PM.
CANEHDN is offline   Reply With Quote

Reply

Mac Forums > Special Interests > Web Design and Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:16 AM.

Mac News | Mac Rumors | iPhone Game Reviews | iPhone Apps

Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 2002-2009, MacRumors.com, LLC