473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Adding <td> to a <table> through Onclick

106 100+
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 2182
Dormilich
8,658 Expert Mod 8TB
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 100+
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
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>...
8
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...
4
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"...
2
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...
2
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
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...
5
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);...
4
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...

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.