I'm trying to get the row contents by selecting the tr element which has a unique id.
This is what i have so far, i'm fairly new to this, and really unsure why this isn't working.
var value = $('tr#'+idd).find('input[type=text]').map(function() { return $(this).attr("value"); }).get();
I've tried changing the id so it's not unique and it does receive data. So just confused why this statement doesn't.
Any help is appreciated
while ($record = mysql_fetch_array($entrys))
{
echo "<tr id='" . $record['id'] . "'>";
echo "<td>" . "<input type='text' id='id' name='id' value=" . $record['id'] . " ></td>";
echo "<td>" . "<input type='text' id='make' name='make' value=" . $record['make'] . " ></td>";
echo "<td>" . "<input type='text' id='fuel' name='fuel' value=" . $record['fuel'] . " ></td>";
echo "<td>" . "<input type='text' id='transmission' name='transmission' value=" . $record['transmission'] . " ></td>";
echo "<td>" . "<input type='text' id='size' name='size' value=" . $record['size'] . " ></td>";
echo "<td>" . "<input type='text' id='doors' name='doors' value=" . $record['doors'] . " ></td>";
echo "<td>" . "<input type='hidden' id='hidden' name='hidden' value=" . $record['id'] . " ></td>";
echo "<td>" . "<button name='update' onclick=edit('".$record['id']."') >Edit</button>";
echo "<td>" . "<button id='delete' name='delete' onclick=del('".$record[id]."') value=" . $row . " >Delete</button> </td>";
echo "</tr>";
}
echo "</table>";
Try this:
return $(this).val();
Your last line:
echo "<td>" . "<button id='delete' name='delete' onclick=del('".$record[id]."') value=" . $row . " >Delete</button> </td>";
.$record[id]." - should be .$record['id']." like the others.
Related
The following code will output as shown in the attached picture.
Select the value of the Select box in test16 and press the "test19" button, the value of the Select box you want to modify.I want to make the value delivered to php.
I want to know how to deliver the value of the select box in php and how to receive the value delivered.
<?php
if($result = mysqli_query($link, $sql)){
$test = 'test';
if(mysqli_num_rows($result) > 0){
echo "<table id='datatable1' class = table style = 'width: 100%; background-color:#dee2e6'>";
echo "<thead >";
echo "<tr>";
echo "<th>No</th>";
echo "<th>test1</th>";
echo "<th>test2</th>";
echo "<th>test3</th>";
echo "<th>test4</th>";
echo "<th>test5</th>";
echo "<th>test6</th>";
echo "<th>test7</th>";
echo "<th>test8</th>";
echo "<th>test9</th>";
echo "<th>test10</th>";
echo "<th>test11</th>";
echo "<th>test12</th>";
echo "<th>test13</th>";
echo "<th>test14</th>";
echo "<th>test15</th>";
echo "<th>test16</th>";
echo "<th>test17</th>";
echo "<th>test18</th>";
echo "<th>test19</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['chart_num'] . "</td>";
echo "<td>" . $row['chart_name'] . "</td>";
echo "<td>" . $row['visit'] . "</td>";
echo "<td>" . number_format($row['total_medical_bills']) . "</td>";
echo "<td>" . number_format($row['total_amount']) . "</td>";
echo "<td>" . number_format($row['amount_asked']) . "</td>";
echo "<td style = 'font-weight: bold'>" . number_format($row['medical_bills_payment']) . "</td>";
echo "<td style = 'font-weight: bold'>" . number_format($row['personal_liability_amount']) . "</td>";
echo "<td style = 'font-weight: bold'>" . number_format($row['non_payment']) . "</td>";
echo "<td>" . $row['insurance_division'] . "</td>";
echo "<td>" . $row['division'] . "</td>";
echo "<td>" . number_format($row['cash_amount_received']) . "</td>";
echo "<td>" . number_format($row['card_amount_received']) . "</td>";
echo "<td style = 'font-weight: bold'>" . number_format($row['treatment_fees_difference']) . "</td>";
echo "<td>" . $row['treatment_fees_check_division'] . "</td>";
echo "<td><select name='". $test ."'>";
echo "<option value='". $test ."'>First</option>";
echo "<option value='". $test ."'>Second</option>";
echo "<option value='". $test ."'>Third</option>";
echo "</select></td>";
echo "<td>" . $row['treatment_fees_check'] . "</td>";
echo "<td>" . $row['treatment_fees_check_modify'] . "</td>";
echo "<td>";
if($row['medical_bills_payment'] == $row['personal_liability_amount'] + $row['non_payment']){
echo "수정불가";
}
else{
echo "<a href='treatment_fees_check_update.php?id=". $row['id'] ." title='수정' data-toggle='tooltip'><span class='icon ion-edit'></span></a>";
}
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
mysqli_free_result($result);
}
}
else{
echo "ERROR: Could not able to execute $sql2. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
Since you can have a lot of select boxes, you will need give them an ID so we can reference the respective field. Let's add/change your code as below:
$rowCount=0;
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
...
echo "<td><select id='MySelect".$rowCount."' name='". $test ."'>";
echo "<option value='". $test ."'>First</option>";
echo "<option value='". $test ."'>Second</option>";
echo "<option value='". $test ."'>Third</option>";
echo "</select></td>";
...
echo "<td>";
if($row['medical_bills_payment'] == $row['personal_liability_amount'] + $row['non_payment']){
echo "수정불가";
}
else{
echo '<span class="icon ion-edit"></span>';
}
echo "</td>";
$rowCount++;
EDIT: I missed to add $rowCount++; before close while block. Sorry.
At the end of your document, before close body tag you add:
<script>
function GetMySelectValue(select,objId){
document.location.href= "yoursite.com/treatment_fees_check_update.php?id="+objId+"&myselect="+document.getElementById(select).value;
}
</script>
In treatment_fees_check_update.php you get id and select value:
$rowid=$_GET['id'];
$myselect=$_GET['myselect'];
Hope it can help you.
The principles for what you need is to asign a id to each one of the options in the dropdown, so you can send the id of tha specific value, compare with that same id in the database if exists then you will have the column with the value that you need to modify in the database, but first bring and add the proper id of each one of the options in the select.
I have a looped table displaying the results of a drop-down form post (lotstatus). I want to be able to change the color of the text based on the value they selected in the form.
if($result = mysqli_query($conn, $sql)){ if(mysqli_num_rows($res) > 0){ echo "
<table class='table table-bordered table-striped' width='100%' data-pagination='true' data-search='true'>"; echo "
<thead>"; echo "
<tr>"; echo "
<th>Status</th>"; echo "
<th>Street #</th>"; echo "
<th>Street Name</th>"; echo "
<th>City</th>"; echo "
<th>Parcel ID</th>"; echo "
<th>Lot # (Unit)</th>"; echo "
<th>Contract Signed Date</th>"; echo "
<th>Closing Date</th>"; echo "
<th>Action</th>"; echo "</tr>"; echo "</thead>"; echo "
<tbody>"; while($row = mysqli_fetch_array($res)){ echo "
<tr>"; echo "
<td>" . "
<div class='statuscolor'>". $row['lotstatus'] . "</div>". "</td>"; echo "
<td>" . $row['streetnumber'] . "</td>"; echo "
<td>" . $row['streetname'] . "</td>"; echo "
<td>" . $row['city'] . "</td>"; echo "
<td>" . $row['parcelid'] . "</td>"; echo "
<td>" . $row['lotnumber'] . "</td>"; echo "
<td>" . $row['contractsigneddate'] . "</td>"; echo "
<td>" . $row['closingdate'] . "</td>"; echo "
<td>"; echo "<a class='btn btn-info mr-2 mt-2' href='readLot.php?id=". $row[' id '] ."' title='View' data-toggle='tooltip'><span style='margin-left: 7px;' class='la la-file-o ks-icon'></span></a>"; echo "<a class='btn btn-warning mr-2 mt-2' href='updateLot.php?id=". $row['
id '] ."' title='Edit ' data-toggle='tooltip'><span style='margin-left: 7px;' class='la la-pencil ks-icon'></span></a>"; echo "
<a class='btn btn-danger mt-2' href='deleteLot.php?id=". $row[' id '] ."' title='Delete ' data-toggle='tooltip'><span style='margin-left: 7px;' class='la la-close ks-icon'></span></a>"; echo "</td>"; echo "</tr>"; } echo "</tbody>"; echo "</table>";
// Free result set mysqli_free_result($result); } else{ echo "
<p class='lead'><em>No Lots were found.</em></p>"; } }
Here in the form I'm using: The user selects lot status - I want to change the color of the status based on what they chose.
<select class="form-control" value="<?php echo $lotstatus; ?>" id="lotstatus" name="lotstatus">
<option value="NA">N/A</option>
<option value="Executed">Executed</option>
<option value="Not Interested">Not Interested</option>
<option value="Hold">Hold</option>
<option value="Title Ordered">Title Ordered</option>
<option value="Vetting">Vetting</option>
<option value="Survey Ordered">Survey Ordered</option>
<option value="Lean Search Ordered">Lean Search Ordered</option>
<option value="Clear to Close">Clear to Close</option>
<option value="Closed">Closed</option>
</select>
I've tried styling the option value and also tried selecting the text() value of the field. Nothing is working... HELP!
First you need to add each row the status:
<tr class=\"Executed\">"; echo "
<tr class=\"Hold\">"; echo "
With JS you can add to the parent <table> the selected status:
$('select#lotstatus').on('change', function() {
$('table').attr('status', $(this).val());
});
Then, in your css you need to set the color that you want for each status:
table[status="Executed"] tr.Executed .statuscolor { color: red; }
table[status="Hold"] tr.Hold .statuscolor { color: green; }
table[status="Closed"] tr.Closed .statuscolor { color: yellow; }
Maybe you need to add an "id" to the table to avoid interferences with other tables.
I have a row of data, which when clicked, show information about the object.
But I also have a button on the row, which when clicked performs some jquery wizzardry.
Anyway, I can't seem to prevent the row click and just fire the button stuffs.
I've tried:
return false;
e.preventDefault();
e.stopPropagation();
This is the function.
$('#check_container').on('click', '.show_sub_orgs', function(e) {
e.preventDefault();
e.stopPropagation();
return false;
I have all 3 in there at the moment, but that's just for example. Although I have tried all 3 in there, but I have also tried each one separately.
Heres the HTML
<div class="row" id="check_container">
<div id='table_holder' class="col-md-12" >
<table id="org_table" class="sortable table table-striped tablesorter">
<?php
if(empty($org_data2)) {
// if there is no data for the selected filter
echo "There are no organisations set up.";
} else {
echo "
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Sub Orgs</th>
<th>Locations</th>
<th>Users</th>
<th>Compliance</th>
<th>O/D Checks</th>
<th>O/D Training</th>
<th>Renewal</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
";
foreach ($org_data2 as $orgs) {
if(!$orgs->descendant) {
echo "<tr id='" . $orgs->org_id . "' class='edit_org_row clickable'>";
echo "<td>" . (($orgs->ancestor)?'<div id="' . $orgs->org_id . '" class="show_sub_orgs btn btn-primary btn-xs" data-toggle="tooltip" title="Show Sub-Orgs"><i class="fa fa-expand" aria-hidden="true"></i></div>':'') . "</td>";
echo "<td data-title='Name'>" . $orgs->org_name . "</td>";
echo "<td data-title='Sub Orgs' class='text-center'></td>";
echo "<td data-title='Locations' class='text-center'>" . $orgs->locations . "</td>";
echo "<td data-title='Users' class='text-center'>" . $orgs->users . "</td>";
echo "<td data-title='Compliance' class='text-center'></td>";
echo "<td data-title='O/D Checks' class='text-center'>" . $orgs->checks . "</td>";
echo "<td data-title='O/D Training' class='text-center'>" . $orgs->training . "</td>";
echo "<td data-title='Renewal'>" . date("d/m/Y", strtotime($orgs->renewal_date)) . "</td>";
echo "<td data-title='Actions'><div data-id='3' id='" . $orgs->org_id . "' class='btn admin_login btn-success btn-sm' data-toggle='tooltip' title='Login as customer'>Login</div><div data-id='2' id='" . $orgs->org_id . "' class='btn btn-danger btn-sm' data-toggle='tooltip' title='Disable customer'>Disable</div></td>";
echo "</tr>";
}
}
}
?>
</tbody>
</table>
</div>
</div>
What am I doing wrong?
When you delegate to a child element you need to use e.stopImmediatePropigation()
Jquery uses it's own event system and this will stop any execution on the elements delegated to from the parent. e.stopPropigation() will allow all events delegated from the same parent to fire
$('#check_container').on('click', '.show_sub_orgs', function(e) {
e.preventDefault();
e.stopImmediatePropagation();
})
echo '<div class="col-lg-10 col-lg-offset-1 panel">' . "<table id='data' class='table'>
<tr>
<th></th>
<th>Document No</th>
<th>AWB NO</th>
<th>Order Id</th>
<th>Forms</th>
<th>Extras</th>
</tr>";
foreach ($cancel as $key => $value)
{
echo "<tr>";
echo "<td>" . "<input type='checkbox' name='name1' id='checkit$checkitCounter' />" . "</td>";
echo "<td>" . $value[$d] . "</td>";
echo "<td>" . $value[$a] . "</td>";
echo "<td>" . $value[$o] . "</td>";
echo "<td>" . $value[$f] . "</td>";
echo "<td>" . $value[$e] . "</td>";
echo "</tr>";
}
echo "</table></div>";
This above table is generated using php echo with checkbox generated every iteration.
<div style="padding-left:600px;">
<a href='#' class='btn btn-primary btn-md' id='button' style="margin-right:1000px;" onclick='checkit()'
role='button'>Continue..</a>
</div>
The above button is supposed to run a javascript function given below:
function checkit {
var x = document.getElementById("checkit").checked;
if (x == false) {
alert('All items are not removed,pls remove and continue');
}
else {
window.location = "tst.php";
}
}
The above JavaScript doesn't seem to be functioning properly as even though i have checked none of the boxes it just stays on the same page.
Example:
<div style="padding-left:600px;"> <a href='#' class='btn btn-primary btn-md' id='button' style="margin-right:1000px;" onclick='checkit()' role='button'>Continue..</a>
</div>
<input type='checkbox' name='name1' class='checkit' />
<input type='checkbox' name='name1' class='checkit' />
<input type='checkbox' name='name1' class='checkit' />
<input type='checkbox' name='name1' class='checkit' />
<input type='checkbox' name='name1' class='checkit' />
<input type='checkbox' name='name1' class='checkit' />
And js:
function checkit() {
var boxes = document.querySelectorAll(".checkit");
arr = [];
for (i = 0; i < boxes.length; i++) {
arr.push(boxes[i]);
}
console.log(arr);
function is_checked(val) {
return val.checked == true;
}
checked = arr.filter(is_checked);
console.log(checked);
if (checked.length != boxes.length) {
alert('All items are not removed,pls remove and continue');
} else {
window.location = "tst.php";
}
}
Demo: https://jsbin.com/cukuzeweza/edit?html,js,output
I have made a light version of your code and the rest is left to your development logic.
You have had a lot small problems in your code, like function in JavaScript needed (), the usage of single and double quotes, missing call the JavaScript function etc.
I have created a dummy array for test, but again you could do what you like to achieve your code.
Here is the working solution:
<?php
$cancel = ["checkBox1", "checkBox2", "checkBox3"];
echo "<div><table id='data' class='table'>
<tr>
<th></th>
<th>Document No</th>
</tr>";
foreach ($cancel as $value)
{
echo "<tr>";
echo "<td><input type='checkbox' name='name1' id='$value' onchange='checkIt(\"$value\");' /></td>";
echo "<td>" . $value . "</td>";
echo "</tr>";
}
echo "</table></div>";
?>
<script>
function checkIt(checkBoxId) {
var x = document.getElementById(checkBoxId).checked;
console.log("x" + checkBoxId + " is " + x);
}
</script>
You can see in your console the results of your checkbox.
I've been playing with this code for the past 2 hours. I simply cannot find the error. With the code below, the table header and body display, but the headers are not sortable. I've tried various incarnations of the script code, but to no avail. What am I missing?
<!DOCTYPE html>
<head>
<script type="text/javascript" src="./jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="./Mottie-tablesorter-c1ce076/js/jquery.tablesorter.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$("table").tablesorter();
}
);
</script>
</head>
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "SECRET", "SECRET", "SECRET");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt select query execution
$sql = "SELECT * FROM persons";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class=\"tablesorter\">";
echo "<thead>";
echo "<tr>";
echo "<th>First Name</th>";
echo "<th>Last Name</th>";
echo "<th>Email</th>";
echo "<th>FFID</th>";
echo "<th>Street</th>";
echo "<th>City</th>";
echo "<th>State</th>";
echo "<th>Zip</th>";
echo "<th>Home Fire Dept</th>";
echo "<th>Shirt Size</th>";
echo "<th>Additional Shirts</th>";
echo "<th>Friday Class</th>";
echo "<th>Saturday Class</th>";
echo "<th>Sunday Class</th>";
echo "</tr>";
echo "</thead>";
while($row = mysqli_fetch_array($result)){
echo "<tbody><tr>";
echo "<td>" . $row['first_name'] . "</td>";
echo "<td>" . $row['last_name'] . "</td>";
echo "<td>" . $row['email_address'] . "</td>";
echo "<td>" . $row['ffid_num'] . "</td>";
echo "<td>" . $row['address_street'] . "</td>";
echo "<td>" . $row['address_city'] . "</td>";
echo "<td>" . $row['address_state'] . "</td>";
echo "<td>" . $row['address_zip'] . "</td>";
echo "<td>" . $row['fire_dept'] . "</td>";
echo "<td>" . $row['wants_tshirt'] . "</td>";
echo "<td>" . $row['shirt_size'] . "</td>";
echo "<td>" . $row['additional_shirts'] . "</td>";
echo "<td>" . $row['friday_class'] . "</td>";
echo "<td>" . $row['saturday_class'] . "</td>";
echo "<td>" . $row['sunday_class'] . "</td>";
echo "</tr></tbody>";
}
echo "</table>";
// Close result set
mysqli_free_result($result);
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
</html>
Just add and outside the while loop.
echo "</thead><tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['first_name'] . "</td>";
echo "<td>" . $row['last_name'] . "</td>";
echo "<td>" . $row['email_address'] . "</td>";
echo "<td>" . $row['ffid_num'] . "</td>";
echo "<td>" . $row['address_street'] . "</td>";
echo "<td>" . $row['address_city'] . "</td>";
echo "<td>" . $row['address_state'] . "</td>";
echo "<td>" . $row['address_zip'] . "</td>";
echo "<td>" . $row['fire_dept'] . "</td>";
echo "<td>" . $row['wants_tshirt'] . "</td>";
echo "<td>" . $row['shirt_size'] . "</td>";
echo "<td>" . $row['additional_shirts'] . "</td>";
echo "<td>" . $row['friday_class'] . "</td>";
echo "<td>" . $row['saturday_class'] . "</td>";
echo "<td>" . $row['sunday_class'] . "</td>";
echo "</tr>";
}
echo "</tbody></table>";
I have had a similar problem. It seems the style is critically important as well.
I looked at the source of the example e.g. http://tablesorter.com/docs/example-trigger-sort.html and the only thing missing was the style.
In my case I added:
< link href="http://mottie.github.io/tablesorter/css/theme.default.css" rel="stylesheet" >
and the columns became sortable.
The critical part of the style is I think that it includes the buttons for sorting:
.tablesorter-default thead .headerSortUp,
.tablesorter-default thead .tablesorter-headerSortUp,
.tablesorter-default thead .tablesorter-headerAsc {
background-image: url(data:image/gif;base64,R0lGODlhFQAEAIAAACMtMP///yH5BAEAAAEALAAAAAAVAAQAAAINjI8Bya2wnINUMopZAQA7);
border-bottom: #000 2px solid;
}
.tablesorter-default thead .headerSortDown,
.tablesorter-default thead .tablesorter-headerSortDown,
.tablesorter-default thead .tablesorter-headerDesc {
background-image: url(data:image/gif;base64,R0lGODlhFQAEAIAAACMtMP///yH5BAEAAAEALAAAAAAVAAQAAAINjB+gC+jP2ptn0WskLQA7);
border-bottom: #000 2px solid;
}