i have to show and hide a div after click on a text in a span. I have many generated from a loop and i would like click sur every #mod and show me the hidden div. But the hidden div is showed just if i click on the first #mod. How can i make all the #mod a I make this code, but it work just for only one and not for all. Where i m wrong?
<tbody>
<form action="#" method="post" enctype="multipart/form-data" name="actionpost">
<?php
global $wpdb;
$articles = $wpdb->get_results( "select * from {$wpdb->prefix}mic_articles");
?><?php
foreach ($articles as $article){
$url = get_home_url() . "/" . strtolower( str_replace( " ", "-", normalize( $article->titre ) ) );
echo "
<tr class='alternate' valign='top'>
<th class='check-column' scope='row'> <input type='checkbox' name='article[]' value='$article->id'></th>
<td class='column-columnname'><a href='$url'><strong>$article->titre</strong></a>
<div class='row-actions'>
<span id='mod'><a href='#'>Modifier</a> </span> | <span style='color:red' class='supp'>Corbeille</span>
</label>
</div>
</td>
<td class='column-columnname'></td>
</tr>";
}
?>
<?php
?>
</tbody>
</table>
<script>
$('#mod').click(function() {
$('#modification').toggle("slide");
});
</script>
You need the handler to attach the the event. try add the ready
$( document ).ready(function() {
$('#mod').click(function() {
$('#modification').toggle("slide");
});
});
Id in span tag, it has to be unique. You can use a class instead.
<span class="mod">...</span>
$( document ).ready(function() {
$('.mod').click(function() {
$('#modification').toggle("slide");
});
});
Related
I have an html table with bootstrap styling, and in the right side I have checkboxes in each row, but when I select them and click 'Write Report' button it doesn't go to next page, it doesn't do anything as if I didn't click anywhere.
I am new to all this HTML, Bootstrap and PHP so probably there is a stupid mistake I am making somewhere.
Here is my table:
<table id="usetTable" class="display compact" data-toggle="table" data-classes="table table-hover table-condensed" data-row-style="rowColors" data-striped="true" data-sort-name="Quality" data-sort-order="desc" data-pagination="true" data-click-to-select="true">
<thead>
<th data-field="state" data-checkbox="true">Dev.no</th>
<th>IMEI</th>
<th>Report comment</th>
</thead>
<tbody>
<form method="post">
<?php if (!empty($devices)) { ?>
<?php foreach ($devices as $device) : ?>
<tr id="tr-id-2" class="tr-class-2">
<td>
<input type="checkbox" name="devices[<?php echo $device["id"] ?>]" value="<?php echo $device["id"] . $dev_comment ?>">
<?php echo $device["device_no"] ?>
</td>
<td>
<?php echo $device["serial_imei"] ?>
</td>
<td>
<div class="input-group">
<textarea name="dev_comment[<?php echo $device["id"] ?>]" placeholder="comment" rows="1" cols="50"><?php echo $dev_comment; ?></textarea>
</div>
</td>
</tr>
<?php endforeach; ?>
<?php } ?>
</br>
<div id="wrapper">
<button class="btn" type="submit" name="report">Write report</button>
</div>
</form>
</tbody>
</table>
</div>
<script>
$(document).ready(function() {
$('#usetTable').DataTable();
});
</script>
I tried to post only the minimal code to reproduce this error even though I am using dynamic data so its kinda difficult to reproduce this way but in case you want to do that, just user hardcoded data in the table and remove the array fields.
P.S. the table is looking perfectly fine, the only problem is with selecting the rows and going to next page.
[Here is a screenshot][1] [1]: https://i.stack.imgur.com/IidBA.png
EDIT:
I am using jQuery function now and it works but the table lost pagination:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
$(document).ready(function() {
$('#usetTable').DataTable();
$(function() {
//Assign Click event to Button.
$("#btnGet").click(function() {
//Loop through all checked CheckBoxes in GridView.
$("#usetTable input[type=checkbox]:checked").each(function() {
var row = $(this).closest("tr")[0];
});
});
});
});
</script>
if I remove this: src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"
the table looks good but checkboxes dont work anymore.
Title is maybe misleading, but i try you explain it.
My table of users
and When i click on the cross I want open only div with id for example as # in table(id=1, id=2...)
So here is my php code:
$select = "SELECT ... from ...";
$data = mysqli_query($connect, $select);
$count = 0;
echo "<table>
<tr>
<th>#</th>
<th>Name</th>
</tr>";
while ($query = mysqli_fetch_array($data)) {
$counter++;
echo "<tr>
<th>{$counter}</th>
<td>{$query["name"]}</td>
<td><a href='xxx.php?id={$query["id"]}'><i class='ion-edit'></i></a><i class='ion-close-round'></i>
<div class='modal'> //modal have of course display none!
<div class='mContent'>
<div class='mHeader'>
<h2>Modal Header</h2>
</div>
<div class='mMiddle'>
<a href='xxx.php?id={$query['id']}'>delete</a>
</div>
<div class='modal-footer'>
<h3>Modal Footer</h3>
</div>
</div>
</div></td></tr>";
}
echo "</table>\n";
Jquery:
$('.ion-close-round').on('click', function () {
$('.modal').css("display", "block");
});
this script "open" every modal of course, but i want open only modal with given id
Thanks for your help all
You can use $.next() to target the .modal that comes after .ion-close-round
$('.ion-close-round').on('click', function () {
$(this).next('.modal').css("display", "block");
});
The selector . is a class selector.
You want to use the ID selector which is #
The ID selector is stricter as only one element on an HTML page can have a given ID, so your ID is 'modal', it would only work on the first element with the ID of modal.
I'm trying to created a select box in my form and display the image that is selected in the select box next to it. I know it requires jquery or something and I have no clue when it comes to that. If anyone can help or point me in the right direction that would be awesome!!!
<table width="100%">
<tr>
<td>
<select id="icon" name="icon" class="form-control select2">
<?php foreach ($icons as $icon) { ?>
<option value="<?php echo $icon['link']; ?>">
<?php echo $icon['name']; ?>
</option>
<?php } ?>
</select>
</td>
<td align="center" id="iconPreview">
Image Here
</td>
</tr>
</table>
i found this jquery snippet but it doesn't display anything on change...
JQuery:
<script>
$(document).ready(function() {
$("#icon").change(function() {
$("#iconPreview").empty();
if ( $("#icon").val()!="" ){
$("#iconPreview").append("<img src=\"" + $("#icon").val() + "\" />");
}
else{
$("#iconPreview").append("displays image here");
}
});
});
</script>
You'll need to add jQuery if you want to use jQuery in the head, so in your document in the <head> add this line:
<script src="http://code.jquery.com/jquery-1.12.0.min.js"></script>
Then give the TD you want the image in a class:
<td class="imageHere" align="center" id="seleced_image">
Then, at the bottom of your page (or a .js page if you want to link it) add this:
<script>
$(function(){
$('#icon').change(function(){
var image = $('#icon').val();
$('#seleced_image').html("<img src='" + image + "' alt='description' />");
});
});
</script>
This jQuery is saying "Everytime the #icon dropdown changes, load the image into the <td>
This is the simplest way to do it without learning any jQuery. Otherwise, I suggest you learn jQuery or better yet, javascript.
Changes made:
Its better to work with IDs than classes on cases like this.
There is a value within a div. This value is not stored in a div but was actually coming from an html table which I extract using this syntax :
$('table#showalluporders tbody tr').click(function() {
var tableData = $(this).closest("tr").children("td").map(function() {
return $(this).text();
}).get();
$('#txtono').val($.trim(tableData[0])); /* Order No */
**$('#txtdiv').text($.trim(tableData[4]));** /* File Name */
});
Syntax of div in which the value #txtdiv is showing :
<div id="txtdiv"></div>
Now, the problem is - I want to put value of div in a PHP variable so that it can be included in the image src:
<img src="<?php bloginfo('template_url');?>/savelabel/<?php $imgval ?>" alt=""/>
How can I achieve this? As required here is my code :
<div class="bx1">
<div id="txtdiv"></div>
</div>
<script>
var link_base = "<?php echo bloginfo('template_url').'/savelabel/'; ?>" ;
var img_name = $('#txtdiv').html();
$('#imgid').attr('src', link_base + img_name);
</script>
<div class="bx2">
<img id="imgid" src="" alt="" class="imgsty" />
</div>
<div class="bx3">
<label class="lblsty">Order No.</label>
<label class="colonsty">:</label>
<input id="txtono" type="text" name="txtono" value="" readonly class="txtosty" /><br /><br />
</div>
<div style="float:left; width:100%; height:10pt"></div>
<!-- Table 1 -->
<?php
$selquery = "SELECT t_ordid, file_name FROM utmp_orders;
?>
<div class="t1cls">Order No.</div>
<div id="tabstatbox1" class="scroll">
<table id="showalluporders">
<thead><tr><th></th><th></th><th></th><th></th></tr></thead>
<?php
if (empty($retrv)){
die("No Record Found." . mysqli_error($connection));
}
else {
while($retrvarr1 = mysqli_fetch_assoc($retrv)){
<tbody>
<tr>
<td><?php echo $retrvarr1["t_ordid"]; ?></td>
<td id="blocksty"><?php echo $retrvarr1["file_name"]; ?></td>
</tr>
</tbody>
<?php }} ?>
</table>
<script type="text/javascript">
$('table#showalluporders tbody tr').click(function() {
var tableData = $(this).closest("tr").children("td").map(function() {
return $(this).text();
}).get();
$('#txtono').val($.trim(tableData[0])); /* Order No */
$('#txtdiv').text($.trim(tableData[4])); /* File Name */
});
</script>
</div>
Layout of my screen is somewhat like this.
Block 1
[ img1.jpg ] <-- div id="txtdiv"
< Image Block > Order No. : [ 1 ]
Block 2
Order No.--------Order Date------------ Status
1--------------15-2-2015---------------Paid
2--------------15-2-2015---------------Paid
3--------------15-2-2015---------------Paid
4--------------15-2-2015---------------Paid
Block 3
Submit - Button
Scenario: when the user clicks a row of "Block 2 Table" file name of the image in other hidden column will be shown in "Block1 div" and from there through code image will be displayed.
I think this is a three step process.
First, save your base url as a JS variable:
var link_base = "<?php echo bloginfo('template_url').'/savelabel/'; ?>" ;
Next, retrieve the value from the div:
var img_name = $('#txtdiv').html();
Last, put all that into the src:
$('#your_img_id').attr('src', link_base + img_name);
In a table I display several links whose value (user id) is extracted from a database. By clicking on the link appears a modal pop up in which I would like to pass the selected value.
Here is the table:
<table>
<tr>
<td>Username</td>
<td>Id</td>
</tr>
<?php
include ‘db_connection.php’;
$sql = "SELECT * FROM users";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $row[userID]?></td>
<td>
<div id='basic-modal'>
<a href="?id=<?php echo $row[userID]?>" class='basic'>Show</a>
</div>
</td>
</tr>
<?php } ?>
</table>
If I click on the link Show appears the modal pop up:
<div id="basic-modal-content">
<?php
if(isset($_GET[‘userID’])){
$userID = $_GET[‘userID’];
echo ‘UsuerID: ‘ .$userID;
}
?>
</div>
This is the script I used
jQuery(function ($) {
$('#basic-modal .basic').click(function (e) {
$('#basic-modal-content').modal();
return false;
});
});
Since I have little familiarity with the jQuery framework I would like to ask you how can I pass the selected value within the modal and then use it.
jquery allows you to use the .data() attribute
<div id='basic-modal'>
<a href="?id=<?php echo $row[userID]?>" data-mydata="<?php echo $row[userID]?>" class='basic'>Show</a>
</div>
and then u can retrieve data from 'data-mydata' attribute:
jQuery(function ($) {
$('#basic-modal .basic').click(function (e) {
$('#basic-modal-content')
.text($(this).data('mydata'))
.modal();
return false;
});
});