PDA

View Full Version : Help with Dynamic text boxes



sheraz79
10-01-2008, 09:33 AM
Hi There,

How are you,

I have a order form ,that has a option to add text boxes dynamically.
So the user can add boxes as they like and enter their details in these text boxes.

there are some fixed text boxes are present on this form.I have no problem getting values/data from these text boxes.I set it up to send details from this form to my email address.

I'm wondering how can I get data from dynamically text boxes that are add by user.

Thank You

God Bless You.

maneetpuri
10-04-2008, 01:21 PM
Hi,

For accessing the values of dynamically generated text boxes you will have to use the same logic or loop on the submitted form page as the one you have used for generating the dynamic text boxes.

An example scenario, if you know that every time a text box is generated its name would be something like txt_n, where 'n' is the number of the text box generated. What you will have to do is create a hidden field in the form which gets incremented every time a text box is generated. Then on the page that is called after the form is submitted there write a loop to parse the environmental variable storing the form value by generating the names in the same pattern and execute the loop equal to the number of boxes generated.

It might sound confusing to you, but this is how it works. If you can show me the page on which this is happening then I will be able to better comment and explain exactly how you will do it.

Regards,

Maneet
LeXolution IT Services
Web Development Company (http://www.lexolutionit.com)

sheraz79
10-05-2008, 07:22 PM
Thank you so much.

here is the details.

<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 2</title>
</head>

<body>


<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>dynamic</title>
</head>

<body>
<HEAD>

<TITLE>dynamic</TITLE>


<script language="javascript">

<!--
var rownum=1

function addRow(el)
{
targEl=document.getElementById(el);
var tbody = targEl.getElementsByTagName("tbody")[1];
rownum=Number(targEl.getElementsByTagName('tr')[(targEl.rows.length-1)].getElementsByTagName('td')[0].getElementsByTagName('input')[0].value);
rownum+=1;
var row = document.createElement("TR");


var cell0 = document.createElement("TD");
var inp0 = document.createElement("INPUT");
inp0.setAttribute("type","text");
inp0.setAttribute("name","Sno" + rownum);
inp0.setAttribute("size","2");
inp0.setAttribute("value", rownum);
inp0.setAttribute("disabled", true);
cell0.appendChild(inp0);


var cell1 = document.createElement("TD");
var inp1 = document.createElement("INPUT");
inp1.setAttribute("type","text");
inp1.setAttribute("name","Product" + rownum);
inp1.setAttribute("size","45");
inp1.setAttribute("value","");
cell1.appendChild(inp1);


var cell2 = document.createElement("TD");
var inp2 = document.createElement("INPUT");
inp2.setAttribute("type","text");
inp2.setAttribute("name","Manufacture" + rownum);
inp2.setAttribute("size","45");
inp2.setAttribute("value","");
cell2.appendChild(inp2);


row.appendChild(cell0);
row.appendChild(cell1);
row.appendChild(cell2);

tbody.appendChild(row);
}

function validate(the)
{
i=document.FORM1.Drop1.value;
alert(i);
i= document.FORM1.Drop2.value;

alert(i)

submit();


}


-->




</SCRIPT>



</HEAD>
<BODY>


<P>

<form method="POST" action="--WEBBOT-SELF--" onSubmit="">
<!--webbot bot="SaveResults" u-file="_private/form_results.csv" s-format="TEXT/CSV" s-label-fields="TRUE" s-email-address="" s-email-format="TEXT/PRE" startspan --><input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--webbot bot="SaveResults" endspan i-checksum="43374" --><p>&nbsp;</p>

<p align=center> <b>

<U>ABCTOZ</U>
</P>
<p>
&nbsp;</p>

<p>
&nbsp;</p>

<p>
&nbsp;</p>

<p>

<br>
<br>

</p>

<table id="1st" cellSpacing=1 cellPadding=1 border=10>
<TR >
<TD rowSpan=2 size=4>&nbsp;No</TD>
<TD colSpan=2>
<CENTER >
<p>Please Enter Your Order Details Here </p>
</CENTER>
<p align="left"><b>1st Store Name</b><input type="text" name="T1" size="47"></p>

</TD>
</TR>
<TR>
<TD>
<CENTER>
<p> <b>
Product</b></p>
</CENTER></TD>
<TD>
<CENTER>
<p><select size="1" name="D1">
<option selected value="Select">Select</option>
<option>Manufacturer</option>

<option>Size/Topping</option>
</select></p>
</CENTER></TD>
</TR>
<tbody>
<TR name=row1 >
<TD ><input type="text" name="Sno" size=2 value=1 disabled></TD>
<TD><input type="text" name="Product" size=45></TD>
<TD><input type="text" name="Manufacture" size=45></TD>

</TR>
</tbody>
</table>

<p>


<input type="button" value="Add A Box For 1st Store!" onClick="addRow('1st');">&nbsp; </p>
</b>

<table id="2nd" cellSpacing=1 cellPadding=1 border=1>
<TR >
<TD rowSpan=2 size=4>&nbsp;No</TD>
<TD colSpan=2>
<CENTER >
<p>Please Enter Your Order Details Here</p>
</CENTER>
<p align="left"><b>2nd Store Name<input type="text" name="T2" size="47"></b></p>

</TD>
</TR>
<TR>
<TD>
<CENTER>
<p>Product</p>
</CENTER></TD>
<TD>
<CENTER>
<p><select size="1" name="D2">
<option selected value="Select">Select</option>
<option value="Manufacturer">Manufacturer</option>
<option value="Size/Topping">Size/Topping</option>

</select></p>
</CENTER></TD>
</TR>
<tbody>
<TR name=row1 >
<TD ><input type="text" name="Sno" size=2 value=1 disabled></TD>
<TD><input type="text" name="Product" size=45></TD>
<TD><input type="text" name="Manufacture" size=45></TD>

</TR>
</tbody>
</table>

<p>

<input type="button" value="Add A Box For 2nd Store!" onClick="addRow('2nd');">&nbsp; </p>


<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>


</body>

</html>

maneetpuri
11-04-2008, 11:15 AM
Hi,

You are using JavaScript for creating text boxes and naming them as: -

"Sno" + rownum
"Product" + rownum
"Manufacture" + rownum

Along with this create a hidden field (say rowcount) and increment it every time you are creating a new row. Now in the PHP script you will get all the text fields as well as the hidden field, the value of the hidden field will tell you how many new times new text boxes were added to access the values of all the added text boxes run a while loop starting from 1 till the value of rowcount and if in the loop you will write

echo ${"Sno" . $i_count} then it will show the value of the SNO text box created at the the i_count position, where i_count is the variable incrementing the loop in the while. Similarly you can access the values for Product as well as Manufacture.

Let me know if you have any doubts!

Cheers,

~Maneet
LeXolution IT Services
Web Design Services (http://www.lexolutionit.com)