473,394 Members | 1,781 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,394 software developers and data experts.

dynamically text box add and value concat by coma

57
i want dynamically text box add and its value concat by coma. and at last show all data store in php variable. please help me.................

i use this following code to dynamically add text box.

Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3.     <TITLE> Add/Remove dynamic rows in HTML table </TITLE>
  4.     <SCRIPT language="javascript">
  5.         function addRow(tableID) {
  6.  
  7.             var table = document.getElementById(tableID);
  8.  
  9.             var rowCount = table.rows.length;
  10.             var row = table.insertRow(rowCount);
  11.  
  12.             var cell1 = row.insertCell(0);
  13.             var element1 = document.createElement("input");
  14.             element1.type = "checkbox";
  15.             cell1.appendChild(element1);
  16.  
  17.             var cell2 = row.insertCell(1);
  18.             cell2.innerHTML = rowCount + 1;
  19.  
  20.             var cell3 = row.insertCell(2);
  21.             var element2 = document.createElement("input");
  22.             element2.type = "text";
  23.             cell3.appendChild(element2);
  24.  
  25.         }
  26.  
  27.         function deleteRow(tableID) {
  28.             try {
  29.             var table = document.getElementById(tableID);
  30.             var rowCount = table.rows.length;
  31.  
  32.             for(var i=0; i<rowCount; i++) {
  33.                 var row = table.rows[i];
  34.                 var chkbox = row.cells[0].childNodes[0];
  35.                 if(null != chkbox && true == chkbox.checked) {
  36.                     table.deleteRow(i);
  37.                     rowCount--;
  38.                     i--;
  39.                 }
  40.  
  41.             }
  42.             }catch(e) {
  43.                 alert(e);
  44.             }
  45.         }
  46.  
  47.     </SCRIPT>
  48. </HEAD>
  49. <BODY>
  50.  
  51.     <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
  52.  
  53.     <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
  54.  
  55.     <TABLE id="dataTable" width="350px" border="1">
  56.         <TR>
  57.             <TD><INPUT type="checkbox" name="chk"/></TD>
  58.             <TD> 1 </TD>
  59.             <TD> <INPUT type="text" /> </TD>
  60.         </TR>
  61.     </TABLE>
  62.  
  63. </BODY>
  64. </HTML>
  65.  
  66.  
Mar 9 '10 #1
5 4480
gits
5,390 Expert Mod 4TB
what is the exact problem that you have ... does the posted code work or do you have an error? just saying to want something doesn't provide enough to answer something except you expect someone to do all the work for you ... so please specify the problem a bit more ...

kind regards
Mar 9 '10 #2
RamananKalirajan
608 512MB
Hope this sample would help you out,

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!-- Its important to define the DocType for HTML -->
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <script type="text/javascript">
  5. function doThis()
  6. {
  7.    var myTab = document.getElementById('myTable');
  8.    var row=myTab.rows.length; 
  9.    var y=myTab.insertRow(row);
  10.  
  11.    var a=y.insertCell(0);
  12.    var xx= document.createElement('input');
  13.    xx.type="text";
  14.    a.appendChild(xx); 
  15.  
  16.    var c=y.insertCell(1);
  17.    var xx= document.createElement('input');
  18.    xx.type="button";
  19.    xx.value="Remove";
  20.    if(window.ActiveXObject)    
  21.     {
  22.         xx.onclick="removeThis(this)"; 
  23.     }
  24.     else
  25.     {
  26.         xx.onclick = function(){removeThis(this);}; 
  27.     }
  28.  
  29.    c.appendChild(xx); 
  30.     if(window.ActiveXObject)    
  31.     {
  32.      c.innerHTML = c.innerHTML;     // This is a work around for IE. It will refresh the container
  33.     }
  34.   }
  35. function removeThis(ths)
  36. {
  37.    var rIndex = ths.parentNode.parentNode.rowIndex;
  38.    alert("rIndex = "+rIndex);
  39.    document.getElementById('myTable').deleteRow(rIndex);
  40.  
  41. }
  42.  
  43. function alertValue()
  44. {
  45.     var valStr="";
  46.     var myTab = document.getElementById('myTable');
  47.    var row=myTab.rows.length; 
  48.     for(var i=1;i<row;i++)
  49.     {
  50.         var x=myTab.rows[i].cells;  
  51.         valStr+= x[0].firstChild.value+",";
  52.     }
  53.     alert(valStr);
  54. }
  55. </script>
  56.  
  57. </head>
  58. <body>
  59. <br/>
  60. <input type="button" value="Add" onclick="doThis()">
  61. <br/><br/>
  62. <table id="myTable" border="1" cellspacing="5" cellpadding="5">
  63. <tr>
  64. <th>Name</th>
  65. <th></th>
  66. </tr>
  67. </table>  
  68. <input type="button" value="Alert Values" onclick="alertValue()">
  69. </body>
  70. </html>
Thanks and Regards
Ramanan Kalirajan
Mar 9 '10 #3
Noorain
57
Thanks for this solution.

i also want to store this value in php command. how php command use in javascript.
Mar 10 '10 #4
gits
5,390 Expert Mod 4TB
you would either have to post a form or use an XMLHttpRequest to transfer the data to a php-script on the webserver ...
Mar 10 '10 #5
RamananKalirajan
608 512MB
I am not good in PHP. May be some other experts will help you out.

Thanks and Regards
Ramanan Kalirajan
Mar 10 '10 #6

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

Similar topics

35
by: .:mmac:. | last post by:
I have a bunch of files (Playlist files for media player) and I am trying to create an automatically generated web page that includes the last 20 or 30 of these files. The files are created every...
1
by: FaensenD | last post by:
Consider the following XML document <root> <PersonStreet>24 Miller Street</PersonStreet> <PersonZIP>12345</PersonZIP> <PersonCity>Munich</PersonCity> <CompanyStreet>24 Miller...
4
by: Dica | last post by:
i need to dynamically add a web control to a page without using placeHolder. i'm looping through all the files in a folder and creating a table row as string for each file. the contol is to be...
1
by: daldridge | last post by:
I have a unique-elements/sorting question (who doesn't?), but haven't yet been able to get appropriate template/select/for-each processing working. I don't fully grok the Muenchian technique yet...
3
by: pbd22 | last post by:
Hi. How do I add the runat=server attribute on a buttonfield link dynamically? thanks!
18
by: Academia | last post by:
I let the use modify the text of a combobox and then I replace the selected item with the new text (in Keyup event). But if he sets the Text property to an empty string ("") that sets the...
1
by: CAM123 | last post by:
I have added: <br><xsl:value-of select="Line" /></br> to my XSLT stylesheet to get a line per repeating block. When I view the output as XML it looks perfect - one line per block. However...
4
by: Craig Buchanan | last post by:
I dynamically add data-bound templates to a gridview in my ascx control. while this works correctly when the gridview is databound to the datatable, i'm having issues on postback. i would like...
7
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a...
7
by: kirkgilbert | last post by:
I am trying to do an onchange event in a form using a text field. The form is tied to a record set that is part of a repeated region. One the first record when I edit the data it works perfectly. ...
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...
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
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.