473,656 Members | 2,997 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding <td> to a <table> through Onclick

106 New Member
I have a table at which i need to add fields in it whenever the user clicks on the Add button , here's my trial but seems sth is wrong :
Expand|Select|Wrap|Line Numbers
  1. function AddTool()
  2.     {
  3.  
  4.           formdiv = document.getElementById('1');
  5.           formdiv.innerHTML = formdiv.innerHTML +'<td align='center'><a href='#'><img border='0' src='../images/delete.gif'></td> ';
  6.     }
thats the Js function
and thats the table which is generated through looping:
Expand|Select|Wrap|Line Numbers
  1. $query=mysql_query("select * from textures"); while($row=mysql_fetch_array($query))
  2.  {
  3.     echo "<div id='1'"></div>;                                
  4.   echo "<td align='center'>$row[texture_name]</td>";
  5.   echo"<td align='center'><a href='#'><img border='0' src='../images/delete.gif'></td>";
  6.   echo "</tr>";
  7.     }                          
  8.  
any help is greatly appreciated
Nov 5 '08 #1
2 2202
Dormilich
8,658 Recognized Expert Moderator Expert
some notes:
- opening <tr> is missing (typo?)
- strictly speaking, "1" is not a valid id and an id must not occur more than once (currently you add the same id to every row)
- more strictly speaking, a <div> belongs into <td> not outside
- if innerHTML is not supported use the DOM methods (createElement( ), appendChild(),. ..), a table row can be accessed as _table_.rows[_row_number_]
- be careful where to add the table cell, it may break your table layout

regards
Nov 5 '08 #2
jessy
106 New Member
Okay,Now i made it and the new Row is added successfully to the table
but i wonder how can write a JS variable inside HTML

Expand|Select|Wrap|Line Numbers
  1. formdiv.innerHTML = formdiv.innerHTML +'<td align=center>JS VARIABLE</td>'+'<td align=center><a href=#><img border=0 src=../images/delete.gif></td>';
Nov 6 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2501
by: Philo | last post by:
How do I select all <div> tags except those which contain a <table> tag somewhere within them? Example XML: <********************** sample input ***********************> <txtSectionBody> <div> <span>
8
4660
by: bearclaws | last post by:
I am looping through a list of categories and want to display the list horizontally (instead of vertically). I want to create a single row with 4 list items in each cell of the row. I thought this would work but I get this error: "End tag 'xsl:if' does not match the start tag 'ul'." Any thoughts?
4
6631
by: A.S. | last post by:
Hi, I have the following simple code: <TABLE><TR> <TD BGCOLOR="#FFFFFF" ONCLICK="myform.color.value = this.bgcolor">hello</TD> </TR></TABLE> <FORM ACTION="hello.cgi" NAME="myform" ID="myform">
2
11206
by: js | last post by:
I have a table rendered with XSLT. The first column has a radio button controls for user to make a selection for a particular row. All the values in the remaining columns are all concated with a &#xA0; (blank). I need to retieve the text in each cell of that row if the radio button on that row is clicked. Each <TD> has a numeric ID so that I can use it with document.getElementById().innerText method. I use Javascript to assign some...
2
5760
by: bissatch | last post by:
Hi, I am trying to use JavaScript to write a table column on a web page. The code is as follows: <html> <head> <script> function displaycount() {
5
4590
by: Magnus Blomberg | last post by:
Hello! I have a table with several rows with text. I want to make the complete cell (or row) clickable as a link/href. Writing <a href...><td>bla bla</td></a> is not possible. If this is possible I have to add several spaces to the text (bla ) to make the clickable area larger. If I have to do this, how to disable the feature that formats the text as a link (becames blue and underlined).
5
6481
by: Jason | last post by:
Hello, I am trying to dynamically create a table, then set its <td>'s onclick: var table = document.createElement("table"); var row = table.insertRow(-1); var td = row.insertCell(-1); td.onclick = myfunction; function myfunction(event) { alert(event);
4
2358
by: John | last post by:
I am attempting to make a table data row editable once clicked on but I am not sure how to show the <tdwith two different states. I've got it to the point where the <tdis hidden then appears within a cfinput when clicked on, but not sure where to go from here. Thanks for looking! <script language="javascript"> function showField(thisID){ //alert("which: "+which+" more stuff here");
2
3014
by: markszlazak | last post by:
I'm a relatively slow response of table cells changing their background color with mouseover/our in IE6 (Win 2K) but the response is fine (fast) in Firefox. Why? The code is below. Sorry about the length. <html> <head> <title>Rapid Blocking Interface</title> <style> .calendar {
0
8296
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8598
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1598
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.