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

Creating Dynamic User Friendly Form

I created a dynamic form in javascript. Am unable to get those values in to php to display. I need all details. If i add 10 rows the i need to display those all values. Can any one help me for that code.

Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3.     <TITLE> Add/Remove dynamic rows in HTML table </TITLE>
  4.  
  5.  <script type="text/javascript" src="script.js">
  6.  
  7. // JavaScript Document
  8. var c=0;
  9.         function addRow(tableID) {
  10.  
  11.  
  12.             var table = document.getElementById(tableID);
  13.  
  14.             var rowCount = table.rows.length;
  15.             var row = table.insertRow(rowCount);
  16.  
  17.             var cell1 = row.insertCell(0);
  18.             var element1 = document.createElement("input");
  19.             element1.type = "checkbox";
  20.             cell1.appendChild(element1);
  21.  
  22.              var type=document.forms[0].element.value;
  23.             var value=document.forms[0].field_value.value;
  24.             var name="txt"+c;
  25.             document.forms[0].hid.value="txt"+c;
  26.             var cell2 = row.insertCell(1);
  27.             cell2.innerHTML =document.forms[0].field_name.value;
  28.  
  29.             var cell3 = row.insertCell(2);
  30.             var element2 = document.createElement("input");
  31.  
  32.             element2.setAttribute("type", type);
  33.             element2.setAttribute("value", value);
  34.             element2.setAttribute("name", name);
  35.  
  36.             if(document.forms[0].element.value =='area'){
  37.                 var element3 = document.createElement("textarea");
  38.                 cell3.appendChild(element3);
  39.                 c++;
  40.                 document.forms[0].txt.value=c;
  41.             }
  42.             else{
  43.             cell3.appendChild(element2);
  44.             c++;
  45.             document.forms[0].txt.value=c;
  46.             }
  47.  
  48.         }
  49.  
  50.         function setbg(color)
  51.             {
  52.  
  53.             document.getElementById("area").style.background=color
  54.             }
  55.  
  56.         function sz(t) {
  57.             a = t.value.split('\n');
  58.             b=1;
  59.             for (x=0;x < a.length; x++) {
  60.                  if (a[x].length >= t.cols) b+= Math.floor(a[x].length/t.cols);
  61.              }
  62.             b+= a.length;
  63.             if (b > t.rows) t.rows = b;
  64.             }
  65.  
  66.         function deleteRow(tableID) {
  67.             try {
  68.             var table = document.getElementById(tableID);
  69.             var rowCount = table.rows.length;
  70.  
  71.             for(var i=0; i<rowCount; i++) {
  72.                 var row = table.rows[i];
  73.                 var chkbox = row.cells[0].childNodes[0];
  74.                 if(null != chkbox && true == chkbox.checked) {
  75.                     table.deleteRow(i);
  76.                     rowCount--;
  77.                     i--;
  78.                     document.forms[0].txt.value=i;
  79.                 }
  80.  
  81.             }
  82.             }catch(e) {
  83.                 alert(e);
  84.             }
  85.         }
  86.  
  87. </script>
  88. </HEAD>
  89. <BODY><form style="background-color:#F6F7F2; width:100%" action="example_process.php" method="post" name="f1" >
  90. <label>Select Type</label> <SELECT name="element">
  91.  
  92.     <OPTION value="text">Textbox</OPTION>
  93.     <OPTION value="radio">Radio</OPTION>
  94.     <option value="checkbox">Check Box</option>
  95.      <OPTION value="area">Area</OPTION>
  96.  
  97. </SELECT>
  98. <label>Name</label>
  99. <input type="text" name="field_name" value="">
  100. <label>Value</label>
  101. <input type="text" name="field_value" value="">
  102.     <INPUT type="button" value="Add Row" onClick="addRow('dataTable')" />
  103.  
  104.     <INPUT type="button" value="Delete Row" onClick="deleteRow('dataTable')" />
  105.  
  106.     <TABLE id="dataTable" width="350px" border="0">
  107.         <TR>
  108.                <td> </td>
  109.         </TR>
  110.     </TABLE>
  111.  
  112.     <INPUT  align="right" type="submit" value="Save" />
  113.     <input type="hidden" name="txt"/>
  114.     <input type="hidden" name="hid"/>
  115. <textarea id="area" name="info" style="visibility:hidden;" onFocus="this.value=''; setbg('#e5fff3');" onBlur="setbg('white');"onkeyup="sz(this);">Enter your comment here...</textarea>
  116.  </form>
  117. </BODY>
  118. </HTML>
Oct 21 '09 #1
2 3310
Dormilich
8,658 Expert Mod 8TB
if I read your code right, then all the created <input>s have the same name. unless you use "input_name[]" (this is parsed into an array), the <input>s with the same name will overwrite each other.

PS. putting the <input> in a list is a more semantic approach.
Oct 21 '09 #2
Markus
6,050 Expert 4TB
Furthermore, you never show us how you are trying to access the data in PHP. If you are POSTing the data, it will be in the $_POST array.

Do a print_r($_POST); to see what's in that array.
Oct 21 '09 #3

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

Similar topics

2
by: tommy | last post by:
Newbie to the group.....hope you guys can help. I need to be able to have a button at the bottom of a form page (like the submit & reset buttons) to provide the user with a printer friendly...
10
by: Deano | last post by:
I think that just about sums it up. Is there a fix/workaround for this?It's quite annoying behaviour and not user-friendly.thanksMartin
17
by: Fabrice | last post by:
Hi ! I'm looking for a tutorial on how to create a DLL in C (not C++). I don't know whether i can use C for this purpose, but i didn't find any post telling me that i cannot use C. So, if it is...
2
by: LIN | last post by:
Hello, Greetings. I am creating a web site which will contain lot of articles. I had been planning to create simple HTML page on the server everytime i posted a article (eg. article12.html )....
1
by: Hasani \(remove nospam\) | last post by:
The way the system works is, you create a user control (ascx) that will be a template and must implement the interface IPageTemplate. You then create one or more user controls (ascx) that implement...
2
by: Patrick | last post by:
I want to define a set of web-form templates in XML and render the equivalent web-form with ASP.NET, then process any input server controls on the form. Reading the XML file from Page_load is...
5
by: Guillaume BRAUX | last post by:
Hello, What I want to do is to add a userControl to a form class witch is a different class from the one the button is generated. For example, I want to instanciate a label in "class1" and add...
10
by: jflash | last post by:
Hello all, I feel dumb having to ask this question in the first place, but I just can not figure it out. I am wanting to set my site up using dynamic urls (I'm assuming that's what they're...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.