Hi friends,
I am struggling for few days for this issue.
In my appication, I have taken one button for adding row, so when I click
addrow
button row added successfully.
If click multiple times, multiple rows also added.
In added row, I have taken one dropdown box and one text box.
In drop down, I have some items coming from database.
Whenever I select one item, based on that selected item populating value in textbox. So, whenever I try to update multiple rows, that updating rows are not working.
Only first row is updating and the remaining rows are not updated.
Mycode is here.
<SCRIPT language="javascript">
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells[i].innerHTML;
//alert(newcell.childNodes);
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;
break;
}
}
}
</script>
<script>
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
function validateform2(x)
{
//alert(x)
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("tax").value=xmlhttp.responseText;
//alert(tax);
}
}
xmlhttp.open("POST","state-tax.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("key="+x);
}
</script>
<form name="retire" action="state-apportionment-busd.php" method="POST">
<table border="0" align="left" width="100%" bgcolor="#d6eafb" cellpadding="8" cellspacing="1">
<tbody><tr>
<td width="14%" align="center" valign="top" class="tbl-area-tabs"><strong> Business Name</strong></td>
<td width="14%" align="center" valign="top" class="tbl-area-tabs"><strong> Tax ID Employer ID</strong></td>
</tr></table>
<table border="0" align="left" width="100%" bgcolor="#d6eafb" cellpadding="8" cellspacing="1">
=$_COOKIE[="select * from state_apportionment where user_id=$lu"=mysql_query($sql)=mysql_fetch_array($result))
{
?
<tr bgcolor="#FFFFFF">
<td width="14%" align="left" valign="top" style="margin:0px auto;">
<select name="textfield1[]" class="select-box-new" id="state-one" onchange="return validateform2(this.value)">
<option value="">select</option>
=mysql_query(=$lu=mysql_fetch_array($sql))
{
?
<option value="<?php echo $result['basic_name'];?>" <?php if($row['textfield1']==$result['basic_name']){?> selected="selected" ></option>
</select></td>
<td width="14%" align="left" valign="top" style="margin:0px auto;">
<input name="textfield2[]" type="text" id="tax" size="8" value="<?php echo $row['textfield2']; ?>"/>
</td>
<table border="0" align="left" width="100%" bgcolor="#d6eafb" cellpadding="8" cellspacing="1" id="dataTable">
<tr>
<td width="14%" align="left" valign="top" style="margin:0px auto;">
<select name="textfield1[]" class="select-box-new" id="textfield1" id="state-one" onchange="return validateform2(this.value)">
<option value="">select</option>
=mysql_query(=$lu=mysql_fetch_array($sql))
{
?
<option value="<?php echo $result['basic_name'];?>" <?php if($row['textfield1']==$result['basic_name']){?> selected="selected" ></option>
</select></td>
<td width="14%" align="left" valign="top" style="margin:0px auto;">
<input name="textfield2[]" type="text" id="tax" size="8" /></td>
<br><INPUT type="button" value="Add Row" onClick="addRow('dataTable')" />
</table>
</table>
<table align="center">
<tr>
<td align="right" valign="middle"><input type="submit" name="submit" value="Save">
</td>
</tr>
</table>
</form>
//state-apportionment-busd.php
=$_COOKIE[= $_POST[= $_POST[";
//die();
$search_r1=mysql_query("select user_id from state_apportionment_total where user_id=".$lu);
$sql1="select * from state_apportionment where user_id=$lu";
//echo $sql;
$result1=mysql_query($sql1) or die("Query failed $sql1".mysql_error());
if(mysql_num_rows($result1)!=0)
{
$sql1="DELETE FROM state_apportionment WHERE user_id=$lu";
$result1=mysql_query($sql1) or die("Query failed $sql1".mysql_error());
}
foreach($textfield1 as $a => $b)
{
$sql="INSERT INTO state_apportionment VALUES('',$lu,'$textfield1[$a]','$textfield2[$a]')";
//echo $sql;
$result=mysql_query($sql) or die("Query failed $sql".mysql_error());
}
/*else
{
foreach($textfield1 as $a => $b)
{
$sql2="UPDATE retirement_expenses SET textfield1='$textfield1[$a]',textfield2='$textfield2[$a]' where user_id=$lu ";
//echo $sql2;
$result2=mysql_query($sql2) or die("Query failed $sql2".mysql_error());
}}
*/
?>
<script>parent.location='somepage.php?data=update'; </script>
Please give solution.
Thanks & Regards
Mallesh
Email Removed
[Edit]
1. Email removed.
2. Grammatical errors corrected.
[/Edit]