mbeals Posted December 20, 2007 Share Posted December 20, 2007 I built a site to manage incoming tech support calls. The calls come in, are parsed into a database then dynamic tables are built via php to display the info. Anyway, to make entering work orders easier, I need to be able to reformat data into a plain text friendly format and display it (so it can be copied). The easiest thing for me to do is to create a dynamic link for each row of data that pops a javascript alert box with the formatted text. The issue I'm hitting is that it is impossible to highlight and copy text from an alert box. Is there a way to modify the box or to embed a text field in the box to allow this? Any ideas how to do this or something similar? I thought about floating css layers, but want to avoid that for the sake of simplicity and cross browser support. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 20, 2007 Share Posted December 20, 2007 I replied to a thread a couple of weeks ago similar to this question - check it it and see if that is what you are trying to do: http://www.phpfreaks.com/forums/index.php/topic,171221.msg757750.html#msg757750 Quote Link to comment Share on other sites More sharing options...
mbeals Posted December 20, 2007 Author Share Posted December 20, 2007 close but not quite. What I have is a table consisting of name, address, phone number, ect.... that is dynamically loaded by ajax. So I have something like: Name Address Phone John Foo Bar Which when copy/pasted into a normal text editor is messy and unformated. I just need to display that info in a multiline format like: John Foo Bar Where I can copy it to paste into another program. I'm trying to avoid loading a different page, so that if multiple work orders need to be made, there isn't a lot of shifting back and forth. Having the link open in a new window is another option, but I think that is messy when so little info is actually being presented. The alert box is perfect as it is simple to call and simple to dismiss...if I could only access the text in it. Actually, openeing a new browser window wouldn't be bad, as long as I could constrain the size and eliminate the menu and address bar, ect...and prevent it from opening in a tab. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 20, 2007 Share Posted December 20, 2007 What are you doing - displaying the PHP variables (Name,Address,Phone) in a JavaScript alert? Quote Link to comment Share on other sites More sharing options...
mbeals Posted December 21, 2007 Author Share Posted December 21, 2007 Basically. The page runs a mysql query and displays all the results in a table. It builds the table recursively, so every time it pulls the values to build the row, I just generate an alert box using the same values. The base page is in php. The only javascript here is to create the alert box, and the ajax code that is loading the dynamic data (the dynamic table is being loaded into a div by ajax). I need to be able to take all the info in a single row and format it so that I can copy it then paste it into a rich text editor without the formating being all screwed up. Here is an example of what I have working now http://bealsm82.googlepages.com/example.html The actual page builds the tables dynamically, and that example does not. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 21, 2007 Share Posted December 21, 2007 If your adding the variables dynamically; just insert the dynamic variable values in the script I have below; just like you did in the JavaScript Alert. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script language="javascript"> function getAlertInfo(Name,Address,Number) { document.getElementById('thearea').value=""+Name+"\r"+Address+"\r"+Number+""; } </script> </head> <body> <table width="32%" border="0"> <tr> <td width="24%" bgcolor="#CCFFFF"><div align="center"><strong>Name</strong></div></td> <td width="28%" bgcolor="#CCFFFF"><div align="center"><strong>Address</strong></div></td> <td width="48%" bgcolor="#CCFFFF"><div align="center"><strong>Phone</strong></div></td> </tr> <tr> <td><div align="center"><a href="javascript:getAlertInfo('JohnDoe','123 Foo Lane','123-465-7981')" onclick="alert('JohnDoe\n123 Foo Lane\n123-465-7981')">John Doe </a></div></td> <td><div align="center">123 Foo lane </div></td> <td><div align="center">123-465-7981</div></td> </tr> <tr> <td bgcolor="#FFFFCC"><div align="center"><a href="javascript:getAlertInfo('JaneDoe','245 Bar rd','987-987-7897')" onclick="alert('JaneDoe\n245 Bar rd\n987-987-7897')">Jane Doe </a></div></td> <td bgcolor="#FFFFCC"><div align="center">254 Bar rd </div></td> <td bgcolor="#FFFFCC"><div align="center">987-987-7897</div></td> </tr> </table> <br><br> <textarea id="thearea" style="width:300px;height:225px"></textarea> </body> </html> Quote Link to comment Share on other sites More sharing options...
mbeals Posted December 26, 2007 Author Share Posted December 26, 2007 okay, that was my workaround. I just used a div and .innerHTML instead. I was trying to avoid having a permanent element on the page, as with my current layout, I really don't have a place to put it that will make sense or be easy to use. That's why I was trying to use an alert box.... it is only there when you need it, it goes away when you are done, and it is much easier to code and maintain cross browser support for then a floating hidden div. Quote Link to comment Share on other sites More sharing options...
mbeals Posted December 26, 2007 Author Share Posted December 26, 2007 well I got it working. I did something I didn't really want to do, but it seems to be working okay on the versions of firefox and IE that we use. I ended up just making a floating div which I can change the contents of and change the visibility of. I also make it draggable....in essence reinventing the alert box. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.