I make Jquery to read data from db and when I click the list it shown roe data on detail box.
But.... problem: I make div where I show content. I load page with Jquery to div.
but when I do this the row click dont work. I can not understan why. It is shild element but id i understan right when I use getElementById it should to take current row, but no.
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<?php include './config/init.php'; ?>
<html>
<head>
<meta charset="UTF-8">
<title>Biisilista</title>
<script src="./js/jquery-3.2.1.js"></script>
<link href="css/basic.css" rel="stylesheet" type="text/css">
</head>
<body>
<h1>KaraokeBiisit </h1>
<div id="edit" style="display:none">
<div>
<form name="formedit" method="post" action="">
<table id="edittable" border="1" cellspacing="2" cellpadding="1">
<tbody>
<tr>
<td>
<label>Nimi:</label>
</td>
<td>
<input id="nimi" name="nimi" placeholder="Kappaleen nimi" type="text">
</td>
<td>
<label>Levy:</label>
</td>
<td>
<input id="levy" name="levy" placeholder="Levyn tunnus" type="text" width="10px">
</td>
</tr>
<tr>
<td>
<label>Artisti:</label>
</td>
<td>
<input id="artisti" name="artisti" placeholder="Kappaleen esittäjä" type="text">
</td>
<td>
<label>Kieli:</label>
</td>
<td>
<input id="kieli" name="kieli" placeholder="Alkuperäiskieli" type="text" width="20">
</td>
</tr>
<tr>
<td>
<label>Numero:</label>
</td>
<td>
<input id="numero" name="numeron" placeholder="Numero" type="text">
</td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
<div id="pageContent">
</div>
<script src="./js/jquery-3.2.1.js"></script>
<script src="./js/script.js"></script>
</body>
</html>
jQuery(document).ready(function ($) {
$("#pageContent").click(function () {
$('tr').removeClass('selected');
$(this).addClass('selected');
var selectedRow;
selectedRow = $(rivi);
var td = $(selectedRow).children('td');
$('#nimi').val(td[0].innerText);
$('#artisti').val(td[1].innerText);
$('#levy').val(td[2].innerText);
$('#kieli').val(td[3].innerText);
$('#numero').val(td[4].innerText);
console.log("test");
});
$(".clickable-row").on('click', () => {
$('#edit').show();
});
$('#pageContent').load('container.php');
// $('#pageContent').load('biisit.php');
});
function showBiisit() {
console.log("Näytetään sisältö");
$('#pageContent').load('container.php');
}
<?php include './config/init.php'; ?>
<?php
//luodaan tietokantaobjekti
$db = new DataBase();
// tehdään kysely
$db->query("SELECT * FROM kappaleet");
//query("SELECT `id`,`nimi`,`artisti`,`levy`,`kieli`,`numero` FROM `kappaleet`;");
//yhdistetään hakutulokseen
$kappaleet = $db->resultset();
?>
<table id="dataTable">
<tr>
<th>Nimi</th>
<th>Artisti</th>
<th width="100" align="left">Levy</th>
<th width="100" align="left">Kieli</th>
<th width="100" align="left">Numero</th>
</tr>
<?php foreach ($kappaleet as $biisi): ?>
<tr class='clickable-row' >
<td><?php echo $biisi->nimi ?></td>
<td><?php echo $biisi->artisti ?></td>
<td><?php echo $biisi->levy ?></td>
<td><?php echo $biisi->kieli ?></td>
<td><?php echo $biisi->numero ?></td>
</tr>
<?php endforeach; ?>
</table>
try this
...
$("body").on('click', '.clickable-row', function () { //i change this line
$('tr').removeClass('selected');
$(this).addClass('selected');
var selectedRow = $(this);
//selectedRow = $(rivi); idk what is this
var td = selectedRow.children('td');
$('#nimi').val(td[0].innerText);
$('#artisti').val(td[1].innerText);
$('#levy').val(td[2].innerText);
$('#kieli').val(td[3].innerText);
$('#numero').val(td[4].innerText);
console.log("test");
});
...
Related
I'm using jquery-confirm, and I need to capture the name of the element which i clicked to edit.
jQuery and jQuery-confirm
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js"></script>
</head>
PHP
<?php
$products = array(['name'=>'Balloon'],
['name'=>'Bike']);
?>
<table>
<thead>
<tr>
<th>Name</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php foreach($products as $prod) { ?>
<tr>
<td><?php echo $prod['name'] ?></td>
<td><a class="edit" href="#">Edit Product</a></td>
</tr>
<?php } ?>
</tbody>
</table>
SCRIPT
$('a.edit').confirm({
content: '<input type="text" value="$ Name of the product.">'
});
Obs: Where It's written "$ Name of the product", should appear the name of each product that I click.
You can use this.$target to get a tag which is clicked then using .closest('tr').find('td:eq(0)').text() get first td content.
Demo Code :
$('.edit').confirm({
content: function() {
//get closest tr and find get product name..
return '<input type="text" value="' + this.$target.closest('tr').find('td:eq(0)').text().trim() + '">'
}
});
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js"></script>
<table>
<thead>
<tr>
<th>Name</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Abc
</td>
<td><a class="edit" href="#">Edit Product</a></td>
</tr>
<tr>
<td>
Abcd
</td>
<td><a class="edit" href="#">Edit Product</a></td>
</tr>
<tr>
<td>
Abce
</td>
<td><a class="edit" href="#">Edit Product</a></td>
</tr>
</tbody>
</table>
I am having two php files, one contains a form and another to display the content entered and save button. After confirming the details are correct he has to save and the data should be inserted into the table. I have given the code below
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> </script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script>
</head>
<body>
<?php
$roll=$_POST['roll'];
$sname=$_POST['sname'];
$fname=$_POST['fname'];
$gender=$_POST['gender'];
$aadhar=$_POST['aadhar'];
$caste=$_POST['caste'];
?>
<div class="container container-center">
<!-------------total panel------------------------------------>
<div class="panel-info">
<!------panel heading------>
<div class="panel-heading">
<h2><center><u>STUDENT DETAILS</u></center></h2>
</div> <!-panel heading->
<div class="panel-body">
<form method="post" action="">
<table align="center" border="0">
<tbody>
<tr>
<td rowspan="7"><?php echo"<img src=/photo/$roll.jpg width='200px' height='300px' id='photo'>"; ?></td>
<td>1. Roll Number & Photo:</td>
<td><?php echo"".strtoupper($roll).""; ?></td>
</tr>
<tr>
<td>2. Name of the Student:</td>
<td><?php echo"".strtoupper($sname).""; ?></td>
</tr>
<tr>
<td>3. Name of the Father:</td>
<td><?php echo"".strtoupper($fname).""; ?></td>
</tr>
<tr>
<td>4. Gender:</td>
<td><?php
if($gender=='M')
{ echo"Male";}
else
{echo"Female";}
?></td>
</tr>
<tr>
<td>5. Aadhar Number:</td>
<td><?php echo"$aadhar"; ?></td>
</tr>
<tr>
<td>6. Caste:</td>
<td><?php echo"$caste"; ?></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" id="submit" name="submit" class="btn btn-info" value="save"></td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</div>
<?php
if(isset($_POST['submit']))
{
echo"<script>alert('success')</script>";
}
?>
</body>
when i click the save button then only the data must be saved. but even if not click the save the php code in isset is executing.
the data obtained by $_POST is from the form.
Please help me.
NOTE:
Actually Problem is that, you don't get the data on this page.. in your POST request with given variable so that Please Just Check it . Other Code Is Fine. !! ( Here I am Just Pass Dummy Data ) Like Below.
$roll= '1234';
$sname='XYZ';
$fname= 'ABC';
$gender= 'M';
$aadhar= '123456789100';
$caste= 'A12345';
Solution: You Have To Get DATA Here in post request from your first_php_page form where user enter the details regarding given fields: roll,sname,fname,gender,aadhar,caste
After here in secound_php_page check that Submit button is set then store the values in varable Like below Code:
NOTE: At The End YoU Have To Write The Insert Query On Save Button Click. To Store The data in Database.
<?php
if(isset($_POST['Submit'])){
$roll=$_POST['roll'];
$sname=$_POST['sname'];
$fname=$_POST['fname'];
$gender=$_POST['gender'];
$aadhar=$_POST['aadhar'];
$caste=$_POST['caste'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> </script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script>
</head>
<body>
<?php
/*
$roll=$_POST['roll'];
$sname=$_POST['sname'];
$fname=$_POST['fname'];
$gender=$_POST['gender'];
$aadhar=$_POST['aadhar'];
$caste=$_POST['caste'];
*/
// SET THE DUMMY DATA FOR Result check
$roll= '1234';
$sname='XYZ';
$fname= 'ABC';
$gender= 'M';
$aadhar= '123456789100';
$caste= 'A12345';
?>
<div class="container container-center">
<!-- total panel -->
<div class="panel-info">
<!-- panel heading -->
<div class="panel-heading">
<h2><center><u>STUDENT DETAILS</u></center></h2>
</div>
<!--panel heading -->
<div class="panel-body">
<form method="post" action="">
<table align="center" border="0">
<tbody>
<tr>
<td rowspan="7"><?php echo"<img src=/photo/$roll.jpg width='200px' height='300px' id='photo'>"; ?></td>
<td>1. Roll Number & Photo:</td>
<td><?php echo"".strtoupper($roll).""; ?></td>
</tr>
<tr>
<td>2. Name of the Student:</td>
<td><?php echo"".strtoupper($sname).""; ?></td>
</tr>
<tr>
<td>3. Name of the Father:</td>
<td><?php echo"".strtoupper($fname).""; ?></td>
</tr>
<tr>
<td>4. Gender:</td>
<td><?php
if($gender=='M')
{ echo"Male";}
else
{echo"Female";}
?></td>
</tr>
<tr>
<td>5. Aadhar Number:</td>
<td><?php echo"$aadhar"; ?></td>
</tr>
<tr>
<td>6. Caste:</td>
<td><?php echo"$caste"; ?></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" id="submit" name="submit" class="btn btn-info" value="save"></td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</div>
<?php
if(isset($_POST['submit']))
{
echo"<script>alert('success')</script>";
}
?>
</body>
</HTML>
OUTPUT: DATA Display
AND ONCLICK SAVE
There are few issues with your code, such as:
There's no point having a form and save button(in another page) if you don't have input elements and don't send your data using $_POST superglobal. Create input elements for each of your fields with type="hidden", for example like this:
<td><?php echo strtoupper($roll); ?><input type="hidden" name="roll" value="<?php echo strtoupper($roll); ?>"></td>
Here's the full form code,
// your code
<form method="post" action="">
<table align="center" border="0">
<tbody>
<tr>
<td rowspan="7"><?php echo"<img src=/photo/$roll.jpg width='200px' height='300px' id='photo'>"; ?></td>
<td>1. Roll Number & Photo:</td>
<td><?php echo strtoupper($roll); ?><input type="hidden" name="roll" value="<?php echo strtoupper($roll); ?>"></td>
</tr>
<tr>
<td>2. Name of the Student:</td>
<td><?php echo strtoupper($sname); ?><input type="hidden" name="sname" value="<?php echo strtoupper($sname); ?>"></td>
</tr>
<tr>
<td>3. Name of the Father:</td>
<td><?php echo strtoupper($fname); ?><input type="hidden" name="fname" value="<?php echo strtoupper($fname); ?>"></td>
</tr>
<tr>
<td>4. Gender:</td>
<td>
<?php
if($gender=='M'){
echo"Male";
}else{
echo"Female";
}
?>
<input type="hidden" name="gender" value="<?php echo $gender; ?>">
</td>
</tr>
<tr>
<td>5. Aadhar Number:</td>
<td><?php echo $aadhar; ?><input type="hidden" name="aadhar" value="<?php echo $aadhar; ?>"></td>
</tr>
<tr>
<td>6. Caste:</td>
<td><?php echo $caste; ?><input type="hidden" name="caste" value="<?php echo $caste; ?>"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" id="submit" name="submit" class="btn btn-info" value="save"></td>
</tr>
</tbody>
</table>
</form>
// your code
I don't see any code where you're inserting the form data into the table, you should have a code block like this in another page(where you have displayed the form data and has the save button):
if(isset($_POST['submit'])){
$roll = $_POST['roll'];
$sname = $_POST['sname'];
$fname = $_POST['fname'];
$gender = $_POST['gender'];
$aadhar = $_POST['aadhar'];
$caste = $_POST['caste'];
// your INSERT operation
}
I generating a QR CODE with url as data content, but when i try to print a page where the qr is generated, the qr does not seem to appear yet other content displays. Here is my snippet
<?php
require_once("qrcode.php");
//---------------------------------------------------------
$qr = new QRCode();
// ƒGƒ‰[’ù³ƒŒƒxƒ‹‚ðÝ’è
// QR_ERROR_CORRECT_LEVEL_L : 7%
// QR_ERROR_CORRECT_LEVEL_M : 15%
// QR_ERROR_CORRECT_LEVEL_Q : 25%
// QR_ERROR_CORRECT_LEVEL_H : 30%
$qr->setErrorCorrectLevel(QR_ERROR_CORRECT_LEVEL_L);
$qr->setTypeNumber(4);
$qr->addData("http:/".$_SERVER['REQUEST_URI']."");
$qr->make();
//---------------------------------------------------------
?>
and below is the other content on the page
<div class="invoice-box" id="invoice-box">
<table cellpadding="0" cellspacing="0">
<tr class="top">
<td colspan="2">
<table>
<tr>
<td class="title">
<img src="images/logo.png" style="width:100%; max-width:200px; height:95px;">
</td>
<td>
Invoice #: <?php print $invoice_details->sub_code ?><br>
Created: <?php print date('Y/M/d', strtotime($invoice_details->paid_date)) ?><br>
Due: February 1, 2015
</td>
</tr>
</table>
</td>
</tr>
<tr class="information">
<td colspan="2">
<table>
<tr>
<td>
<br>
<br>
</td>
<td>
<?php print $invoice_details->org ?><br>
<?php print $invoice_details->lname ?> <?php print $invoice_details->fname ?><br>
<?php print $invoice_details->email ?>
</td>
<td>
<?php $qr->printHTML(); ?>
</td>
</tr>
</table>
</td>
</tr>
<tr class="heading">
<td>
Payment Method
</td>
<td>
</td>
</tr>
<tr class="details">
<td>
<?php print $invoice_details->method ?>
</td>
<td>
</td>
</tr>
<tr class="heading">
<td>
Item
</td>
<td>
Price(UGX)
</td>
</tr>
<tr class="item">
<td>
<?php print ucfirst($invoice_details->event) ?> - Summit
</td>
<td>
<?php print number_format($invoice_details->amount) ?>
</td>
</tr>
<tr class="total">
<td></td>
<td>
Total: UGX <?php print number_format($invoice_details->amount) ?>
</td>
</tr>
</table>
</div>
<input type="button" value="Print Div" onclick="PrintElem('#invoice-box')" />
and my printing script
<script type="text/javascript">
function PrintElem(elem)
{
Popup($(elem).html());
}
function Popup(data)
{
var mywindow = window.open('', 'invoice-box', 'height=400,width=600');
mywindow.document.write('<html><head><title>my div</title>');
/*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10
mywindow.print();
mywindow.close();
return true;
}
</script>
Assuming I found the correct library, it has an image creator. What you need to do is use an output buffer around the imagegif (or imagepng) call to capture the image's binary data into a string, then base64 encode the string, and echo that as part of a data URI directly in the src attribute of an img tag.
$img = $qr->createImage(4, 2);
ob_start();
imagegif($img);
imagedestroy($img);
$img = ob_get_clean();
In your HTML
<img src="data:image/gif;base64,<?php echo base64_encode($img);?>">
If you're concerned about support for data URLs, leave out the output buffering, add a unique, random filename as the second parameter to the imagegif call to save it, then echo that filename in the src.
It seems that you're trying to print a black background color which is removed by default from printing. Unfortunately there's no way to force it back programatically in browsers other than Safari and Chrome.
You can force this back for Safari and Chrome by doing:
<div class="invoice-box" id="invoice-box">
<style>
.invoice-box table td: {
-webkit-print-color-adjust: exact !important;
}
</style>
<table cellpadding="0" cellspacing="0">
<tr class="top">
<td colspan="2">
<table>
<tr>
<td class="title">
<img src="images/logo.png" style="width:100%; max-width:200px; height:95px;">
</td>
<td>
Invoice #: <?php print $invoice_details->sub_code ?><br>
Created: <?php print date('Y/M/d', strtotime($invoice_details->paid_date)) ?><br>
Due: February 1, 2015
</td>
</tr>
</table>
</td>
</tr>
<tr class="information">
<td colspan="2">
<table>
<tr>
<td>
<br>
<br>
</td>
<td>
<?php print $invoice_details->org ?><br>
<?php print $invoice_details->lname ?> <?php print $invoice_details->fname ?><br>
<?php print $invoice_details->email ?>
</td>
<td>
<?php $qr->printHTML(); ?>
</td>
</tr>
</table>
</td>
</tr>
<tr class="heading">
<td>
Payment Method
</td>
<td>
</td>
</tr>
<tr class="details">
<td>
<?php print $invoice_details->method ?>
</td>
<td>
</td>
</tr>
<tr class="heading">
<td>
Item
</td>
<td>
Price(UGX)
</td>
</tr>
<tr class="item">
<td>
<?php print ucfirst($invoice_details->event) ?> - Summit
</td>
<td>
<?php print number_format($invoice_details->amount) ?>
</td>
</tr>
<tr class="total">
<td></td>
<td>
Total: UGX <?php print number_format($invoice_details->amount) ?>
</td>
</tr>
</table>
</div>
<input type="button" value="Print Div" onclick="PrintElem('#invoice-box')" />
For browsers like IE and Firefox unfortunately this requires user interaction. See this question for more answers: Printing background-color in Firefox and IE
Finally, i got a way around this, here is my solution
<?php
require_once("qrcode.php");
$qr = QRCode::getMinimumQRCode("http:/".$_SERVER['REQUEST_URI']."", QR_ERROR_CORRECT_LEVEL_L);
$img = $qr->createImage(4, 2);
ob_start();
imagegif($img);
imagedestroy($img);
$img = ob_get_clean();
?>
Then output the qrcode as image with this;
<img src="data:image/gif;base64,<?php echo base64_encode($img);?>">
Thanks to #walf for his solution somehow, hope it helps someone else.
How do I create a jQuery hover to show a div when the mouse is over like twitter repla retweet and favorite?
Here is my HTML:
<div style="display:none;" id="blab">
<?php echo $blab_id; ?>
</div>
<a href="blab.php?id=<?php echo $blab_id; ?>">
<div class="blab_body" id="hover" value="Hide">
<table>
<tr>
<td valign="top">
<img src="<?php echo $profile_pic_info; ?>" class="blab_image" width="50" height="50" />
</td>
<td> </td>
<td>
<table>
<tr>
<td valign="top">
<a href="profile.php?id=$mem_id">
<strong><?php echo $added_fullname; ?></strong>
</a>
<?php echo $added_to_fullname; ?>
</td>
</tr>
<tr>
<td>
<?php echo $blab_body; ?>
</td>
</tr>
<tr>
<td>
<text style="color:gray;">
<?php echo $blab_date; ?>|<?php echo $device; ?>
</text>
</td>
</tr>
</table>
</td>
</tr>
</table>
<div style="background:#000; display:none;" id="id"> </div>
</div>
</a>
<hr />
and here is my JavaScript code:
$('#id').hide();
$('#hover').hover(function () {
var blab_id = $('#blab').text();
$('#id').show();
}, function () {
$('#id').hide();
});
It shows the div for the first one only.
You can only use a certain ID once on the whole page! If you insert more than one copy of this div on the page, your HTML code becomes invalid. That's why jQuery only attaches the event handler to the first element.
The solution is to use class="hover_enabled" instead of id="hover" as it is allowed to add the same class to multiple elements. Here is how you would do it in jQuery:
$('.hover_enabled').hover(function() { ...
The same thing applies to #id.
I have a table with some checkboxes in every row. There is a select element in the table footer with several options. When the user chooses an option, i want to pass the value of any checked checkboxes and the selected option to a php script.
This is the form:
<form name="doall" method="POST" action="action.php">
<table>
<tbody>
<?php for($j=0;$j<count($userToRead);$j++){ ?>
<tr>
<td>
<input type="checkbox" id="selection_<?php echo $j ?>" name="objectSelected[<?php echo $userToRead[$j]['id'] ?>]" value="1"/>
</td>
<td align="center">
<?php echo $userToRead[$j]['id'] ?>
</td>
<td align="center" style="text-align:center;padding-left:15px;background-color:<?php echo $SListsStatus[intval($userToRead[$j]['userstatus'])][1]; ?>;" >
</td>
<td align="center">
<?php echo stripaccenti($userToRead[$j]['user']) ?>
</td>
<td>
<?php echo stripaccenti($SUserType[$userToRead[$j]['type']]['name']) ?>
</td>
<td align="center">
<?php echo stripaccenti($userToRead[$j]['first_name']) ?>
</td>
<td align="center">
<?php echo stripaccenti($userToRead[$j]['last_name']) ?>
</td>
<td align="center">
<?php echo stripaccenti($userToRead[$j]['title']) ?>
</td>
<td class="actBtns">
<a href="#" title="Update" class="tipS">
<img src="images/icons/edit.png" alt="" />
</a>
<a href="#" title="Remove" class="tipS">
<img src="images/icons/remove.png" alt="" />
</a>
</td>
</tr>
<?php } // end for ?>
</tbody>
<tfoot>
<tr>
<td colspan="9">
<div class="itemActions">
<label>Con tutte le selezionate:</label>
<select name="whatDoAll">
<option value="1">Attiva</option>
<option value="2">Disattiva</option>
</select>
<input type="submit" value="Esegui" class="button redB" style="margin: 5px;"/>
</div>
</td>
</tr>
</tfoot>
</table>
</form>
So in every line of my table I have a checkbox where the value is the ID of the db object that I need to modify with my php script.
This is my script:
$('input[type="submit"]').click(function() {
var output = '';
$('input[type="objectSelected"]:checked').each(function(index) {
output += $(this).val() + ", ";
});
alert(output + "is checked!");
});
In the php file i try to retrieve the variable with $_POST['objectSelected'] but the variable is always empty. Also, the script alert is empty.
The tables are create with jquery: if I use a pure html table with pure html checkboxes everything works!
You are doing wrong. You are specifying input type then the code should be:
<script type="text/javascript">
$('input[type="submit"]').click(function() {
var output = '';
$('input[type="checkbox"]:checked').each(function(index) {
output += $(this).val() + ", ";
});
alert(output + "is checked!");
});
</script>
Hope this helps you