By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,589 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,589 IT Pros & Developers. It's quick & easy.

How to retrieve the values of dynamically created textboxes

P: 5
Hi,

I hav created a group of textboxes using a loop and its names are unique and names are assigned using variable ( like <input type=text name=$name1>). Then How can i retrieve the values in that textboxes after a button click with in a loop. Really I cant move from here. Can anyone plz help me..
Part of the my code is given below
<html>
<table>
<?php
// i hav an array "assocArray" and its count is "countarray"
for($i = 1; $i < $countarray ; $i++)
{



$name1=$assocArray[$i].$dat1;

$name2=$assocArray[$i].$d1;


$name3=$assocArray[$i].$d2;
$name4=$assocArray[$i].$d3;
$name5=$assocArray[$i].$d4;
$name6=$assocArray[$i].$d5;
$name7=$assocArray[$i].$d6;


echo"<tr>";
echo "<td><input type=textbox name='.$assocArray[$i].' value='$assocArray[$i]'></td>";
echo "<td><input type=textbox name=$date1 size=3 value=$date1><a href=javascript: openAddcommentsPopup();><img src=images/notes.bmp width=14 height=14 title=Add comments class=addimg/></a></td>";
if($d1<=$cnt) //these are some conditions ,they are all working fine
{
echo "<td><input type=textbox name=$name1 size=3 ><a href=comments.php><img src=images/notes.bmp width=14 height=14 title=Add comments class=addimg/></a></td>";
}
//<img src=images/notes.bmp><a href=javascript: openAddcommentsPopup(); class=addimg></a></nobr></td>";
if($d2<=$cnt)
{
echo "<td><input type=textbox name=name2 size=3><a href='javascript: openAddcommentsPopup();'><img src=images/notes.bmp width=14 height=14 title=Add comments class=addimg/></a></td>";
}

if($d3<=$cnt)
{
echo "<td><input type=textbox name=$name3 size=3><a href=javascript: openAddcommentsPopup();><img src=images/notes.bmp width=14 height=14 title=Add comments class=addimg/></a></td>";
}
if($d4<=$cnt)
{
echo "<td><input type=textbox name=$name4 size=3><a href=javascript: openAddcommentsPopup();><img src=images/notes.bmp width=14 height=14 title=Add comments class=addimg/></a></td>";
}
if($d5<=$cnt)
{
echo "<td><input type=textbox name=$name5 size=3><a href=javascript: openAddcommentsPopup();><img src=images/notes.bmp width=14 height=14 title=Add comments class=addimg/></a></td>";
}
if($d6<=$cnt)
{
echo "<td><input type=textbox name=$name6 size=3><a href=javascript: openAddcommentsPopup();><img src=images/notes.bmp width=14 height=14 title=Add comments class=addimg/></a></td>";
}

echo"</tr>";
}

?>
</table>


<input type="submit" name="savetimesheet" value="Save Time-Track">

//here im able echo the $name1,$name2...
<?php
if(isset($_REQUEST['savetimesheet']))
{

for($i = 1; $i < $countarray ; $i++)
{

$task=$assocArray[$i];


$val1=$_POST['$date1'];

$val2=$_POST[$name1];


$val3=$_POST[$name2];
echo $val3;


$val4=$_POST[$name3];



$val5=$_POST[$name4];



$val6=$_POST[$name5];


$val6=$_POST[$name6];



$query="INSERT INTO timesheetentry(empCode,subtaskCode,dated,workHr)VA LUES($_SESSION[empid],'$task','$date1','$val1'),($_SESSION[empid],'$task','$txtdate1','$val2'),($_SESSION[empid],'$task','$txtdate2','$val3'),($_SESSION[empid],'$task','$txtdate3','$val4'),($_SESSION[empid],'$task','$txtdate4','$val5'),($_SESSION[empid],'$task','$txtdate5','$val6'),($_SESSION[empid],'$task','$txtdate6','$val7')";
$result = $d->query($query);
}
}
?>
Iam not getting the value in the textboxes and so not able to insert the data in the textboxes.

Plz help me.....
Jan 31 '08 #1
Share this Question
Share on Google+
2 Replies


Markus
Expert 5K+
P: 6,050

Please read the forum guidelines


Then post the code with the *correct* code tags.
Jan 31 '08 #2

ifedi
P: 60
Too difficult to sift through your code without code syntax markup.
Feb 8 '08 #3

Post your reply

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