Please see the below while loop which displays the data from a table on loading of the page.
<?php
$idcount;
$jobcount;
$flagcount;
while ( $row = sqlsrv_fetch_array ( $stmt, SQLSRV_FETCH_ASSOC ) )
{
if ($row ['Active'] == '1') {
$flag = 'checked = "checked"';
} else {
$flag = '';
}
echo ("<tr>
<td id = jid$idcount>".$row['JobTypeID']."</td>
<td id = jtype$jobcount>".$row['Jobtype']."</td>
<td align='center'><input id=active$flagcount type='checkbox' name='activecheck' $flag disabled ></td>
<td align='center'><a class = 'toedit' href=# onclick = 'edit($idcount)'>Edit</a> | <a href=# onclick = 'dele($idcount)'>Delete</a></td>
</tr>");
$flag = '';
$idcount += 1;
$jobcount += 1;
$flagcount += 1;
}
?>
My aim is that, when I click on the Edit
link, I need to fill a form with the corresponding row data.
I am intending to use javascript to carry out the processing after the data from the row has been copied, but I am not clear about how to extract the corresponding row data for every Edit link.
I am very new to PHP, so please guide me.
EDIT: Below is the code of the form that I am using
<form name="job" id="ForNew" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<input type="hidden" id="JID" value="">
Job Type <input type="text" id="JType"name="jobtype" value="<?php echo htmlspecialchars($JobTypeValue);?>">
<span class="error"><?php echo $JobTypeErr;?></span><br>
Active? Yes <input type="radio" id = "JRadio"name="radio"<?php if (isset($ActiveValue) && $ActiveValue == "yes") echo "checked"; ?>value="yes">
No <input type="radio" id ="JRadio" name="radio"<?php if (isset($ActiveValue) && $ActiveValue == "no") echo "checked"; ?>value="no">
<span class="error"><?php echo $ActiveErr;?></span><br>
<input type="submit" name="sub" value="Submit!">
</form>
EDIT 2:
I have written the function edit()
as follows, but the value that gets returned is in the form of Object object
. But the value that I need is id name of each specific <td>
, so that I can copy its value into the form textbox.
<script type="text/javascript">
function edit(Data)
{
//Get data with reference to ID
var Num = String(Data);
alert("Entered Function! " + Num);
alert("JID n Data"+$('jid'+Num));
alert("JID value " + Num);
alert(console.log(Num));
$('#JID').val($('jid'+Data).html());
$('#JType').val($('jtype'+Data).html());
$('#JRadio').val($('active'+Data).html());
}
Even if I do not convert var Num = String(Data);
to String, I am getting the same result of Object object
.
$idcount
in edit() function and get the related row with that id