473,238 Members | 1,770 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,238 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>
  5.  <script type="text/javascript" src="script.js">
  7. // JavaScript Document
  8. var c=0;
  9.         function addRow(tableID) {
  12.             var table = document.getElementById(tableID);
  14.             var rowCount = table.rows.length;
  15.             var row = table.insertRow(rowCount);
  17.             var cell1 = row.insertCell(0);
  18.             var element1 = document.createElement("input");
  19.             element1.type = "checkbox";
  20.             cell1.appendChild(element1);
  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;
  29.             var cell3 = row.insertCell(2);
  30.             var element2 = document.createElement("input");
  32.             element2.setAttribute("type", type);
  33.             element2.setAttribute("value", value);
  34.             element2.setAttribute("name", name);
  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.             }
  48.         }
  50.         function setbg(color)
  51.             {
  53.             document.getElementById("area").style.background=color
  54.             }
  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.             }
  66.         function deleteRow(tableID) {
  67.             try {
  68.             var table = document.getElementById(tableID);
  69.             var rowCount = table.rows.length;
  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.                 }
  81.             }
  82.             }catch(e) {
  83.                 alert(e);
  84.             }
  85.         }
  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">
  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>
  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')" />
  104.     <INPUT type="button" value="Delete Row" onClick="deleteRow('dataTable')" />
  106.     <TABLE id="dataTable" width="350px" border="0">
  107.         <TR>
  108.                <td> </td>
  109.         </TR>
  110.     </TABLE>
  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 3300
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
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

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...
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
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...
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 )....
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...
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...
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...
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...
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...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.