I have a table containing multiple rows of input boxes. Entire table and its contents are created dynamically using jQuery Post. Each tr in the table has 7 td and the first td contains a radio button and remaining have text input boxes with values. User has to change the values in the text boxes and click on radio button to update the same. how to get the value if input boxes in the selected row?
I used following function to pop an alert message
jQuery(document).delegate("[name='edit']", "click",function (e) {
alert("clicked");}
This is working. I want to get values of input boxes using this. closest tr input . But do not know the syntax. Please help
the script for creating the table is like this:
echo'<form id="shiftentry" name="shiftentry" >';
echo "Date:<input id=shiftdate value='".$date."'/>";
echo "Unit:<input id=shiftdate value='".$unit."'/>";
echo "Shift:<input id=shiftdate value='".$shift."'/><br/>";
echo "<table><tr><th>No</th><th>Ele</th><th>Location</th><th>Drate </th><th>H3 Val </th><th>Part </th> <th>Iod</th><th>Cont. </th></tr>";
while($row2=mysql_fetch_array($result_sec))
{
echo "<tr>";
echo "<td><input name='edit' type='radio'/></td>";
echo "<td>".++$rc."</td>";
echo "<td><input size='5' id='".$row2['ele']."' value='".$row2['ele']."' /></td>";
echo "<td><input id='".$row2['loc_id']."' value='".$row2['loc']."' /></td>";
echo "<td><input size='5' id='drate".$rc."' value='".$row2['drate']."'/></td>";
echo "<td><input size='5' id='h3".$rc."' value='0' /></td>";
echo "<td><input size='5' id='part".$rc."' value='0' /></td>";
echo "<td><input size='5' id='iod".$rc."' value='0' /></td>";
echo "<td><input size='5' id='cont".$rc."' value='0' /></td>";
echo "</tr>";
}
echo " </table>";
echo '<div align="center">';
echo '<input type="submit" id="submit2" name="submit2" value="Submit" width="30" />';
echo '</div>';
echo '</form>';
Take a look on .closest() and :eq() selector.
jQuery(document).delegate("input[name='edit']", "click",function (e) {
// Will return the Parent Row of clicked input
var _tr = $(this).closest('tr');
// You have 9 td in particular row
// Let's access the 7th input box: <input size='5' id='iod".$rc."' value='0' />
$('td:eq(7) input', _tr).val(); // will return its value
});
Related
while($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<form action='./form_page.php' method='post'>";
echo "<td style='width:9%'>" . $row['studentID']."</td>";
echo "<td style='width:9%'><input type='submit' name='Prove' value='Approve' /></td>";
echo "<td style='width:9%'><input type='submit' name='$count' value='Delete' /></td>";
echo "</form>";
echo "</tr>";
}
I want get the specific student id, but when I reached to here, I dont know how can I get it. If I put $row['studentID'] for button name, I cant use POST['varname'] beacause the name would be different when I select is different.
Submit buttons are identified by their name.
For e.g. If there are 3 forms with 3 submit buttons named Accept1, Accept2 and Accept3.
When user submits a form by clicking on Accept1, the POST variable will be $_POST['Accept1']. Similarly $_POST['Accept2'], $_POST['Accept3'] respectively.
You can also print POST variable to get a clear idea i.e. print_r($_POST).
If i put $row['studentID'] for button name, i cant use POST['varname']
You can loop over all the values in $_POST and see if any of them match the pattern of a student ID.
Alternatively, you can use a button element (which will let you have display text and a value which don't match each other):
<button name="approve"
value="<?php echo htmlspecialchars($row['studentID'])>
Approve
</button>
and then just test for $_POST['approve'].
Try like this..
while($row = mysqli_fetch_assoc($result))
{
echo "<tr><form action='./form_page.php' method='post'>";
echo "<td style='width:9%'>" . $row['studentID']."</td>";
echo "<input type='hidden' name='studentID' value='".$row['studentID']."'>";
echo "<td style='width:9%'><input type='submit' name='Prove' value='Approve'>;
echo "<td style='width:9%'><input type='submit' name='$count' value='Delete'>
</td></form></tr>";
}
By using input type hidden you will be able to get the student id when submit the from. Hope this will help
In my HTML table I have created a button link for each and every row . I need to edit existing rows and add new rows. The links are working perfectly but I need to pass parameters to url .Like for example I f I need to add new rows I need to get the values of the data cells like
echo "<form action=insert_rows.php?machine_ip&crawler_type&keywords&instances_no method=get>";
Its going to the proper link but I am not able to the row data ,its not getting passed, same with existing rows, through submit button I am able submit to the link but I am not able to pass the row values.For existing rows I need to pass the respective primary keys and then access the rows.
My code so far
<style>
input{
width: 100%
}
</style>
<?php
include('db_connect.php');
$conn = db_connect();
mysql_select_db("crawler_status");
$query="Select * from crawler_info";
$result=mysql_query($query);
echo "<table style=width:1000px border=2>";
echo "<tr>";
echo "<td>"."<b>"."Machine IP"."<b>"."</td>";
echo "<td>"."<b>"."Crawler Type"."</b>"."</td>";
echo "<td>"."<b>"."Keywords"."</b>"."</td>";
echo "<td>"."<b>"."No Of Instances"."</b>"."</td>";
echo "<td>"."<b>"."No Of Keywords"."</b>"."</td>";
echo "<td>"."<b>"."Running Status"."</b>"."</td>";
echo "</tr>";
while($row=mysql_fetch_array($result)){
echo "<tr>";
echo "<form action=individual_rows.php method=get>";
echo"<td>". $row['machine_ip']."</td>";
echo "<td>". $row['crawler_type']."</td>";
echo "<td>". $row['keywords']."</td>";
echo "<td>". $row['no_of_instances']."</td>";
echo "<td>". $row['no_of_keywords']."</td>";
echo "<td>". $row['running_status']."</td>";
echo "<td>"."<input type=submit value =EDIT></td>";
echo "</form>";
echo "</tr>";
}
echo "<tr>";
echo "<form action=insert_rows.php?machine_ip&crawler_type&keywords&instances_no method=get>";
echo "<td>"."<input type=text name=machine_ip form=my_form></td>";
echo "<td>"."<input type=text name=crawler_type form=my_form ></td>";
echo "<td>"."<input type=text name=keywords form=my_form></td>";
echo "<td>"."<input type=text name= =instances_no></td>";
echo "<td>"."<input type=text name=keywords_no></td>";
echo "<td>"."<input type=submit value =submit></td>";
echo "</form>";
echo "</tr>";
echo "</table>";
?>
How should I proceed?
action=insert_rows.php?machine_ip&crawler_type&keywords&instances_no
According to above when you are submitting form then action URL get truncated ?machine_ip&crawler_type&keywords&instances_no and only you have working action URL is action=insert_rows.php So according to me you should use hidden field to send data. like
<form action ='action=insert_rows.php' method=get>
<input type=hidden name=machine_ip value= ''>
<input type=hidden name=crawler_type value= ''>
<input type=hidden name=keyword value= ''>
<input type=hidden name=instances_no value= ''>
</form>
where value has your desired value.
You can try hidden field to pass data.
Use
<input type="hidden" name="machine_ip" value="<?php echo $row['machine_ip'] ?>" />
same may be applied for other field.
I don't know how to give the proper title for this problem, so sorry if this is confusing you all.
First, I have a function to append one row inside a table. Each row will have a dropdown ( select tag) with some option that I retrieve from database. To generate the dropdown, I have a get() function that when the page loaded, I get the output of a php file to show the dropdown with data inside it from my database. i put it inside <div align=center class='finish'></div>. From the default condition, there are already 3 rows with the same format, so I need to start the get() from the beginning. But the problem is that I want to set the dropdown inside the new appended row without refreshing the other existing dropdown. the logic is, when I already choose some option from existing dropdown, an then I want to add new row, I don't want to refreshed the dropdown that already selected.
get() for dropdown function:
$.get("getfinishlist.php", function(item) {
$('.finish').html(item);
});
addrow table function for append row:
function addrow_table() { //#p_rows is the tbody of the table
$('#p_rows').append("<tr><td><div align=center><input type='text' size='5' class='section' name='section[]' style='font-size:11px'></div></td>"
+"<td><div class='desc' style='font-size:11px;'></div></td>"
+"<td><div align=center class='finish'></div><input type='hidden' class='hfinish'></td>"
+"<td><div align=center><input type='text' size='5' name='hrd[]' style='font-size:11px'></div></td>"
+"<td><div align=center><input type='text' size='9' name='length[]' class='length' style='font-size:11px'></div></td>"
+"<td><div align=center><input type='text' size='4' class='pc' name='pc[]' style='font-size:11px'></div></td>"
+"<td><div align=center class='kg'>0</div><input type='hidden' class='hkg' name='kg[]'></td>"
+"<td><div align=center class='price'>0</div><input type='hidden' class='hprice' name='price[]'></td>"
+"<td><div align=center class='amount'>0</div><input type='hidden' class='hamount' name='amount[]'></td>"
+"<td><input type='hidden' style='font-size:11px'>"
+"<div align='center'>"
+"<a href='#' id='delrow' style='text-decoration:none;'>"
+"<div style='border:1px solid #a1a1a1;"
+"background:#dddddd;"
+"width:30px;"
+"border-radius:5px;'>"
+"X"
+"</div></a></div></td>"
+"</tr>");
$.get("getfinishlist.php", function(item) { //I know this is wrong because every time I start the function, every dropdown refreshed
$('.finish').html(item);
});
return false;
}
$('#addrow').click(function() { //#addrow is a div
addrow_table();
});
the php file to retrieve the dropdown:
<?php
include "config/koneksi.php";
echo "<select name='finish[]' class='sfinish'>";
$finish = mysql_query("SELECT * FROM harga");
while($readf = mysql_fetch_array($finish)){
echo "<option value='".$readf['finishing']."'>".$readf['finishing']."</option>";
}
echo "</select>";
?>
I appreciate every answer that everyone give to me. Thank you.
I think what you are trying to do is to set the result of the ajax request to the newly added row, in that case
function addrow_table() { //#p_rows is the tbody of the table
//store the added row reference in a variable - use appendTo() to return the newly added element reference
var $row = $("<tr><td><div align=center><input type='text' size='5' class='section' name='section[]' style='font-size:11px'></div></td>" + "<td><div class='desc' style='font-size:11px;'></div></td>" + "<td><div align=center class='finish'></div><input type='hidden' class='hfinish'></td>" + "<td><div align=center><input type='text' size='5' name='hrd[]' style='font-size:11px'></div></td>" + "<td><div align=center><input type='text' size='9' name='length[]' class='length' style='font-size:11px'></div></td>" + "<td><div align=center><input type='text' size='4' class='pc' name='pc[]' style='font-size:11px'></div></td>" + "<td><div align=center class='kg'>0</div><input type='hidden' class='hkg' name='kg[]'></td>" + "<td><div align=center class='price'>0</div><input type='hidden' class='hprice' name='price[]'></td>" + "<td><div align=center class='amount'>0</div><input type='hidden' class='hamount' name='amount[]'></td>" + "<td><input type='hidden' style='font-size:11px'>" + "<div align='center'>" + "<a href='#' id='delrow' style='text-decoration:none;'>" + "<div style='border:1px solid #a1a1a1;" + "background:#dddddd;" + "width:30px;" + "border-radius:5px;'>" + "X" + "</div></a></div></td>" + "</tr>").appendTo('#p_rows');
$.get("getfinishlist.php", function (item) {
//find the finish element in the newly added row
$row.find('.finish').html(item);
});
return false;
}
$('#addrow').click(function () { //#addrow is a div
addrow_table();
});
I have an array of Textbox, by default they are all disabled... Some Textbox are empty some are not based on the return values of my query.
while ($imps_row1 = sqlsrv_fetch_array($stmt_line_util3,SQLSRV_FETCH_ASSOC)) {
echo "<tr>";
echo "<td><input type='text' disabled='disabled' class='txtDis' name='txt1[]' value='".$imps_row1['qualified_borrower']."'></td>";
echo "<td><input type='text' disabled='disabled' class='txtDis' name='txt2[]' value='".$imps_row1['allowed_borrower']."'></td>";
echo "</tr>";
}
Is there any way that the moment the page loads, all the textbox that are not empty will not be disabled?
Something this might work using just php:
while ($imps_row1 = sqlsrv_fetch_array($stmt_line_util3,SQLSRV_FETCH_ASSOC))
{
echo "<tr>";
echo "<td><input type='text' ".(empty($imps_row1['qualified_borrower'])?"disabled='disabled'":'')." class='txtDis' name='txt1[]' value='".$imps_row1['qualified_borrower']."'></td>";
echo "<td><input type='text' ".(empty($imps_row1['allowed_borrower'])?"disabled='disabled'":'')." class='txtDis' name='txt2[]' value='".$imps_row1['allowed_borrower']."'></td>";
echo "</tr>";
}
Just uses a ternary statement to check if the variable you are echo'ing to the value is empty and if so echo's "disabled...".
am having PHP code and javascript to multiply two values .... Here my problem is that ... if i click on the third box or button then only it shows the result .... I want the result on the third box without clicking it .... Help me
<script language="javascript">
function multiply(arg_id)
{
var textValue1 = document.getElementById('CLS'+arg_id).value;
var textValue2 = document.getElementById('rate'+arg_id).value;
document.getElementById('valuation'+arg_id).value = textValue1 * textValue2;
}
</script>
<?php
$a="some query";
$b=mysql_query($a);
while($c=mysql_fetch_array($b))
{
echo "<td>".$CLOSINGstk."</td><input type='hidden' name='CLOSINGstk".$a."' value='".$CLOSINGstk."' id='CLS".$a."'>";
echo "<td><input type='text' name='rate".$a."' id='rate".$a."'></td>";
echo "<td><input type='button' name='valuation".$a."' id='valuation".$a."' onclick='multiply(".$a.");'></td>";
}
?>
Use the following code:
IN PHP CODE:
while($c=mysql_fetch_array($b))
{
echo "<td>".$CLOSINGstk."</td><input type='hidden' name='CLOSINGstk".$a."' value='".$CLOSINGstk."' id='CLS".$a."'>";
echo "<td><input type='text' name='rate".$a."' id='rate".$a."' onblur='multiply(".$a.");'></td>";
echo "<td><input type='button' name='valuation".$a."' id='valuation".$a."'></td>";
}
This will work.
Do some changes in PHP CODE:
while($c=mysql_fetch_array($b))
{
echo "<td>".$CLOSINGstk."</td><input type='hidden' name='CLOSINGstk".$a."' value='".$CLOSINGstk."' id='CLS".$a."'>";
echo "<td><input type='text' name='rate".$a."' id='rate".$a."' onblur='multiply(".$a.");'></td>";
echo "<td><input type='button' name='valuation".$a."' id='valuation".$a."'></td>";
}
It will help I hope..