Here i want to append the div to the parent div using closest function.Here is my code please have a look
var maxAppends = 0;
function add_field(id)
{
var update_new = $('<div class="form-group" style="margin-bottom: 0px">\n\
<label for="field-1" class="col-sm-4 control-label">Documentsss</label>\n\
<div class="col-sm-5">\n\
<div class="fileinput fileinput-new" data-provides="fileinput">\n\
<span class="btn btn-default btn-file"><span class="fileinput-new" >Select file</span><span class="fileinput-exists" >Change</span><input type="file" name="files[]" ></span> <span class="fileinput-filename"></span>×</div></div>\n\<div class="col-sm-2">\n\<strong>\n\
<i class="fa fa-times"></i> Remove</strong></div>');
$(".update_new_"+id).append(update_new);
maxAppends++;
}
<div id="update_new_<?php echo $value->id;?>" class="update_new_<?php echo $value->id;?> item-row">
<div class="form-group mb0" style="margin-bottom: 0px">
<label for="field-1"
class="col-sm-4 control-label">Other Document</label>
<div class="col-sm-5">
<div class="fileinput fileinput-new" data-provides="fileinput">
<?php
if (!empty($value->documents)) {
$uploaded_file = json_decode($value->documents);
}
if (!empty($uploaded_file)):foreach ($uploaded_file as $v_files_image): ?>
<div class="">
<input type="hidden" name="fileName[]"
value="<?php echo $v_files_image ?>">
<span class=" btn btn-default btn-file">
<span class="fileinput-filename"> <?php echo $v_files_image ?></span>
×
</span>
<strong>
<a href="javascript:void(0);" class="RCF"><i
class="fa fa-times"></i> Remove</a></strong>
<p></p>
</div>
<?php endforeach; ?>
<?php else: ?>
<span class="btn btn-default btn-file"><span
class="fileinput-new">Select File</span>
<span class="fileinput-exists"><?= lang('change') ?></span>
<input type="file" name="files[]">
</span>
<span class="fileinput-filename"></span>
<a href="#" class="close fileinput-exists" data-dismiss="fileinput"
style="float: none;">×</a>
<?php endif; ?>
</div>
<div id="msg_pdf" style="color: #e11221"></div>
</div>
<div class="col-sm-3">
<strong><a href="javascript:void(0);" id="update_more" onclick="add_field('<?php echo $value->id;?>');" u_id="<?php echo $value->id;?>" class="addCF item-row-click update_more_<?php echo $value->id;?>"><i
class="fa fa-plus"></i> Add More
</a></strong>
</div>
</div>
</div>
when i click add_field i want a div to append to the parent div with class update_new_<?php echo $value->id;?>,so in order to that i had done a script.please have a look
without using closest function the div is appending but the values of div is not passing the value through post,so i want to do the append function with closest function,please help me to solve
Related
This question already has answers here:
PHP Pass variable to next page
(9 answers)
Closed 1 year ago.
My index.php page has a display of listings from a json file which looks good. But I am trying to send a result of a single listing from that page to another page (result.php). How do I display the results of that single listing to the new page?
Here is the code for my first page that is attached to the json file:
<?php
$filename = file_get_contents("/ListingCollection.json");
$listings = json_decode($filename);
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://kit.fontawesome.com/ac048d9955.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div style="margin-left:150px; margin-right:150px; margin-bottom:150px;">
<?php foreach ($listings as $listing) { ?>
<span style="visibility:hidden;"><?= $listing->Oid; ?></span>
<div class="row align-items-center border-top">
<div class="col-3" style="padding:10px;">
<?= $listing->AdPhoto; ?>
</div>
<div class="row col-8" style="margin-left:10px;">
<div class="col-8 align-items-center">
<h2 style="color:#00471C; width: 700px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" type="button"><?= $listing->AdTitle; ?></h2>
<h3><?= $listing->AdTagLine; ?></h3>
<p><?= $listing->AdTagLine; ?></p>
</div>
<div class="col-4 align-items-start">
<center><h1><?= $listing->ListingPrice; ?></h1><h3>EBITDA: $<?= $listing->EBITDA; ?></h3></center><br><br>
<center><a class="btn btn-primary" href="<?= $listing->WebsiteURL; ?>?<?= $listing->Oid; ?>" role="button">See Listing</a></center>
</div>
</div>
</div>
<?php } ?>
</div>
</body>
</html>
Here is the code to my second page that I want to pull from single listing of index.php file:
<?php
require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
get_header();
$filename = file_get_contents("/ListingCollection.json");
$listings = json_decode($filename);
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://kit.fontawesome.com/ac048d9955.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div style="margin-left:150px; margin-right:150px; margin-top:50px; margin-bottom:50px;">
<?php foreach ($listings as $listing) { ?>
<!-- Ad Header -->
<div class="row align-items-center" style="margin-bottom:25px;">
<div class="col-12">
<h1><?= $listing->AdTitle; ?></h1>
<h3><?= $listing->County; ?>, <?= $listing->State; ?></h3>
</div>
</div>
<!-- Ad Photo -->
<div class="row" style="margin-bottom:25px;">
<div class="row col-8 align-items-center">
<div class="col-12">
<?= print "Your registration is: ".$regValue."."; ?>
<?= $listing->AdPhoto; ?><br><br>
</div>
<!-- Ad Pricing -->
<div class="col-6">
<h2>ASKING PRICE: $<?= $listing->ListingPrice; ?></h2>
</div>
<div class="col-6">
<h2>CASH FLOW: $<?= $listing->CashFlow; ?></h2>
</div>
<!-- Above button info -->
<div class="col-3">Gross Revenue: </div><div class="col-3">$<?= $listing->GrossRevenue; ?> </div><div class="col-3">Inventory: </div><div class="col-3">$<?= $listing->Inventory; ?></div>
<div class="col-3">EBITDA: </div><div class="col-3">$<?= $listing->EBITDA; ?> </div><div class="col-3">Rent: </div><div class="col-3">$<?= $listing->Rent; ?> </div>
<div class="col-3">FF&E: </div><div class="col-3">$<?= $listing->FFandE; ?> </div><div class="col-3">Established: </div><div class="col-3"><?= $listing->YearEstablished; ?> </div><br><br>
<!-- buttons -->
<div class="col-3">
<a class="btn btn-primary" style="width:100%;" type="button" href="">SAVE</a>
</div>
<div class="col-3">
<a class="btn btn-primary" style="width:100%;" type="button" href="">PRINT</a>
</div>
<div class="col-3">
<a class="btn btn-primary" style="width:100%;" type="button" href="">SHARE</a>
</div>
<div class="col-3">
<a class="btn btn-primary" style="width:100%;" type="button" href="">VALUATION REPORT</a>
</div>
<!-- Ad Description -->
<div class="col-12"><br><br><hr><br>
<h2>DESCRIPTION</h2>
<h2><?= $listing->AdTagLine; ?></h2>
<?= $listing->AdDescription ?><br>
<hr><br>
</div>
<!-- Ad Details -->
<div class="col-3">
<h3>Location:</h3>
</div>
<div class="col-9">
<?= $listing->County ?>
</div>
<div class="col-3">
<h3>Building SF:</h3>
</div>
<div class="col-9">
<?= $listing->TotalSqFt ?>
</div>
<div class="col-3">
<h3>Employees:</h3>
</div>
<div class="col-9">
<?= $listing->EmployeeCount ?>
</div>
<div class="col-3">
<h3>Facilities:</h3>
</div>
<div class="col-9">
<?= $listing->AdFacilityDescription ?>
</div>
<div class="col-3">
<h3>Competition:</h3>
</div>
<div class="col-9">
<?= $listing->AdCompetitiveAnalysis ?>
</div>
<div class="col-3">
<h3>Growth & Expansion:</h3>
</div>
<div class="col-9">
<?= $listing->AdOpportunityForGrowth ?>
</div>
<div class="col-3">
<h3>Support & Training:</h3>
</div>
<div class="col-9">
<?= $listing->AdSupportAndTraining ?>
</div>
<div class="col-3">
<h3>Reason for Selling:</h3>
</div>
<div class="col-9">
<?= $listing->AdReasonForSelling ?>
</div>
<div class="col-3">
<h3>Business Website:</h3>
</div>
<div class="col-9">
<?= $listing->WebsiteURL ?>
</div>
</div>
<div class="col-4 bg-light">
<div class="container">
<!-- CHANGE THE URL HERE -->
<div class="col-12">
<form action="https://app.99inbound.com/e/123" method="POST" target="_blank">
<h1 style="text-align: center;"><br>CONTACT US</h1>
<div class="form-group">
<input name="name" type="text" class="form-control" id="name" placeholder="Full Name" required>
<input name="phone" type="phone" class="form-control" id="phone" placeholder="Phone Number" required>
<input name="email" type="email" class="form-control" id="email" placeholder="Enter Email" required>
</div>
<div class="form-group">
<textarea name="message" class="form-control" id="message" rows="5" placeholder="Enter message" required></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<br><hr>
</div>
<div class="row col-12">
<div class="col-6"><p>Business Listed By:<br>
<?= $listing->SellerFirstName; ?> <?= $listing->SellerLastName; ?></p></div>
<div class="col-6"><p><i class="fas fa-phone-square-alt"></i> <?= $listing->SellerPhone; ?></div>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
<?php get_footer(); ?>
</body>
</html>
I might make a subtle change to the link to turn the ?id into a key/value pair, like
<center><a class="btn btn-primary" href="<?= $listing->WebsiteURL; ?>?display=<?= $listing->Oid; ?>" role="button">See Listing</a></center>
Then on the second page
<?php
require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
get_header();
$filename = file_get_contents("/ListingCollection.json");
$display = $_GET['display'];
$listings = json_decode($filename);
$listing=array_filter($listings, function($a) use($display) {
return $a->Oid === $display;
});
$listing = array_values($listing)[0];
// get rid of the loop on this page
// foreach ($listings as $listing) { <-- GONE
?>
<!-- then the rest of your code, using $listing -->
I fixed the problem by doing this to the button:
<?php echo"<a class='btn btn-primary' role='button' href='https://samplesite.com/result.php?" . http_build_query($listing) . "'>See Listing</a>"; ?>
Then echoing the items on the results page.
I need help on this I don't know if it a mistake here because the comment is not displayed, I submit the comment and I see it in the database but it's doesn't show on unfortunately.
popuptweets.php
<?php
include '../init.php';
if (isset($_POST['showpopup']) && !empty($_POST['showpopup'])) {
$tweetID = $_POST['showpopup'];
$user_id = $_SESSION['user_id'];
$tweet = $getFromT->getPopupTweet($tweetID);
$user = $getFromU->userData($user_id);
$likes = $getFromT->likes($user_id, $tweetID);
$retweet = $getFromT->checkRetweet($tweetID, $user_id);
$comments = $getFromT->comments($tweetID);
?>
<div class="tweet-show-popup-wrap">
<input type="checkbox" id="tweet-show-popup-wrap">
<div class="wrap4">
<label for="tweet-show-popup-wrap">
<div class="tweet-show-popup-box-cut">
<i class="fa fa-times" aria-hidden="true"></i>
</div>
</label>
<div class="tweet-show-popup-box">
<div class="tweet-show-popup-inner">
<div class="tweet-show-popup-head">
<div class="tweet-show-popup-head-left">
<div class="tweet-show-popup-img">
<img src="<?php echo BASE_URL.$tweet->profileImage;?>"/>
</div>
<div class="tweet-show-popup-name">
<div class="t-s-p-n">
<a href="<?php echo BASE_URL.$tweet->username;?>">
<?php echo $tweet->screenName;?>
</a>
</div>
<div class="t-s-p-n-b">
<a href="<?php echo BASE_URL.$tweet->username;?>">
#<?php echo $tweet->username;?>
</a>
</div>
</div>
</div>
<div class="tweet-show-popup-head-right">
<button class="f-btn"><i class="fa fa-user-plus"></i> Follow </button>
</div>
</div>
<div class="tweet-show-popup-tweet-wrap">
<div class="tweet-show-popup-tweet">
<?php echo $getFromT->getTweetLinks($tweet->status);?>
</div>
<div class="tweet-show-popup-tweet-ifram">
<?php if(!empty($tweet->tweetImage)){?>
<img src="<?php echo BASE_URL.$tweet->tweetImage;?>"/>
<?php }?>
</div>
</div>
<div class="tweet-show-popup-footer-wrap">
<div class="tweet-show-popup-retweet-like">
<div class="tweet-show-popup-retweet-left">
<div class="tweet-retweet-count-wrap">
<div class="tweet-retweet-count-head">
RETWEET
</div>
<div class="tweet-retweet-count-body">
<?php echo $tweet->retweetCount;?>
</div>
</div>
<div class="tweet-like-count-wrap">
<div class="tweet-like-count-head">
LIKES
</div>
<div class="tweet-like-count-body">
<?php echo $tweet->likesCount;?>
</div>
</div>
</div>
<div class="tweet-show-popup-retweet-right">
</div>
</div>
<div class="tweet-show-popup-time">
<span><?php echo $tweet->postedOn;?></span>
</div>
<div class="tweet-show-popup-footer-menu">
<ul>
<?php if($getFromU->loggedIn() === true){
echo '<li><i class="fa fa-share" aria-hidden="true"></i></a></button></li>
<li>'.(($tweet->tweetID === $retweet['retweetID']) ? '<button class="retweeted" data-tweet="'.$tweet->tweetID.'" data-user="'.$tweet->tweetBy.'"><a href="#"><i class="fa fa-retweet" aria-hidden="true"></i><span class="retweetsCount">'.$tweet->retweetCount.'</span></button>' : '<button class="retweet" data-tweet="'.$tweet->tweetID.'" data-user="'.$tweet->tweetBy.'"><a href="#"><i class="fa fa-retweet" aria-hidden="true"></i><span class="retweetsCount">'.(($tweet->retweetCount > 0) ? $tweet->retweetCount : '').'</span></button>').'</li>
<li>'.(($likes['likeOn'] === $tweet->tweetID) ? '<button class="unlike-btn" data-tweet="'.$tweet->tweetID.'" data-user="'.$tweet->tweetBy.'"><i class="fa fa-heart-o" aria-hidden="true"></i><span class="likesCounter">'.$tweet->likesCount.'</span></button>' : '<button class="like-btn" data-tweet="'.$tweet->tweetID.'" data-user="'.$tweet->tweetBy.'"><i class="fa fa-heart" aria-hidden="true"></i><span class="likesCounter">'.(($tweet->likesCount > 0) ? $tweet->likesCount : '').'</span></button>').'</li>
<li>
<i class="fa fa-ellipsis-h" aria-hidden="true"></i>
<ul>
<li><label class="deleteTweet">Delete Tweet</label></li>
</ul>
</li>';
}else{
?>
<li><button type="buttton"><i class="fa fa-share" aria-hidden="true"></i></button></li>
<li><button type="button"><i class="fa fa-retweet" aria-hidden="true"></i><span class="retweetsCount">RETWEET-COUNT</span></button></li>
<li><button type="button"><i class="fa fa-heart" aria-hidden="true"></i><span class="likesCount">LIKES-COUNT</span></button></button></li>
<?php }?>
</ul>
</div>
</div>
</div><!--tweet-show-popup-inner end-->
<?php if($getFromU->loggedIn() === true){?>
<div class="tweet-show-popup-footer-input-wrap">
<div class="tweet-show-popup-footer-input-inner">
<div class="tweet-show-popup-footer-input-left">
<img src="<?php echo BASE_URL.$user->profileImage?>"/>
</div>
<div class="tweet-show-popup-footer-input-right">
<input id="commentField" type="text" data-tweet="<?php echo $tweet->tweetID;?>" name="comment" placeholder="Reply to #<?php echo $tweet->username;?>">
</div>
</div>
<div class="tweet-footer">
<div class="t-fo-left">
<ul>
<li>
<label for="t-show-file"><i class="fa fa-camera" aria-hidden="true"></i></label>
<input type="file" id="t-show-file">
</li>
<li class="error-li">
</li>
</ul>
</div>
<div class="t-fo-right">
<span id="count">140</span>
<input type="submit" id="postComment" value="Tweet">
<script type="text/javascript" src="<?php echo BASE_URL;?>assets/js/comment.js"></script>
</div>
</div>
</div><!--tweet-show-popup-footer-input-wrap end-->
<?php }?>
<div class="tweet-show-popup-comment-wrap">
<div id="comments">
<?php
foreach ((array)$comments as $comment) {
echo '<div class="tweet-show-popup-comment-box">
<div class="tweet-show-popup-comment-inner">
<div class="tweet-show-popup-comment-head">
<div class="tweet-show-popup-comment-head-left">
<div class="tweet-show-popup-comment-img">
<img src="'.BASE_URL.$comment->profileImage.'">
</div>
</div>
<div class="tweet-show-popup-comment-head-right">
<div class="tweet-show-popup-comment-name-box">
<div class="tweet-show-popup-comment-name-box-name">
'.$comment->screenName.'
</div>
<div class="tweet-show-popup-comment-name-box-tname">
#'.$comment->username.' - '.$comment->commentAt.'
</div>
</div>
<div class="tweet-show-popup-comment-right-tweet">
<p>#'.$tweet->username.' '.$comment->comment.'</p>
</div>
<div class="tweet-show-popup-footer-menu">
<ul>
<li><button><i class="fa fa-share" aria-hidden="true"></i></button></li>
<li><i class="fa fa-heart-o" aria-hidden="true"></i></li>
<li>
<i class="fa fa-ellipsis-h" aria-hidden="true"></i>
<ul>
<li><label class="deleteTweet">Delete Tweet</label></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
<!--TWEET SHOW POPUP COMMENT inner END-->
</div>
';
}
?>
</div>
</div>
<!--tweet-show-popup-box ends-->
</div>
</div>
<?php
}
?>
comment.js
$(function () {
$(document).on('click', '#postComment', function(){
var comment = $('#commentField').val();
var tweet_id = $('#commentField').data('tweet');
if(comment !=""){
$.post('http://localhost/twitter/core/ajax/comment.php', {comment:comment,tweet_id:tweet_id}, function(data){
$('#comments').html(data);
$('#commentField').val("");
});
}
})
});
commnet.php
<?php
include '../init.php';
if (isset($_POST['comment']) && !empty($_POST['comment'])) {
$comment = $getFromU->checkInput($_POST['comment']);
$user_id = $_SESSION['user_id'];
$tweetID = $_POST['tweet_id'];
if (!empty($comment)) {
$getFromU->create('comments',array('comment' => $comment, 'commentOn' => $tweetID, 'commentBy' => $user_id, 'commentAt' => date('Y-m-d H:i:s')));
$comments = $getFromT->comments($tweetID);
$tweet = $getFromT->getPopupTweet($tweetID);
foreach ((array)$comments as $comment) {
echo '<div class="tweet-show-popup-comment-box">
<div class="tweet-show-popup-comment-inner">
<div class="tweet-show-popup-comment-head">
<div class="tweet-show-popup-comment-head-left">
<div class="tweet-show-popup-comment-img">
<img src="'.BASE_URL.$comment->profileImage.'">
</div>
</div>
<div class="tweet-show-popup-comment-head-right">
<div class="tweet-show-popup-comment-name-box">
<div class="tweet-show-popup-comment-name-box-name">
'.$comment->screenName.'
</div>
<div class="tweet-show-popup-comment-name-box-tname">
#'.$comment->username.' - '.$comment->commentAt.'
</div>
</div>
<div class="tweet-show-popup-comment-right-tweet">
<p>#'.$tweet->username.' '.$comment->comment.'</p>
</div>
<div class="tweet-show-popup-footer-menu">
<ul>
<li><button><i class="fa fa-share" aria-hidden="true"></i></button></li>
<li><i class="fa fa-heart-o" aria-hidden="true"></i></li>
<li>
<i class="fa fa-ellipsis-h" aria-hidden="true"></i>
<ul>
<li><label class="deleteTweet">Delete Tweet</label></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
<!--TWEET SHOW POPUP COMMENT inner END-->
</div>
';
}
}
}
?>
Those are all codes I used so how can I solve the problem?
As we have investigated the problem was in missing return
I have this chat box and this go_to_top icon. Is that possible to hide the icon when the box is clicked and open, and display it again when its closed?
This is how it looks in my local host (view extern):
This my ChatBox code
<section class="btn-xs bd-section-5 hidden-xs bd-page-width bd-tagstyles" id="section5" data-section-title="Section">
<div class="bd-container-inner bd-margins clearfix">
<div class=" bd-layoutbox-9 bd-page-width bd-no-margins clearfix">
<div type="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" class="chatbutton bd-container-inner btn btn-default">
<h4 class=" bd-textblock-11 bd-content-element">
<span style="font-weight: normal;">Call us on</span> 0800 0125 888
</h4>
</div>
<div class="panel-collapse collapse" id="collapseOne">
<div class="panel-body">
<ul class="chat">
<li class="left clearfix"><span class="chat-img pull-left">
<img src="./assets/images/<?php echo ($cruise_avatar[0]); ?>.png" alt="<?php echo ($cruise_avatar[0]); ?>" class="img-circle" />
</span>
<div class="chat-body clearfix">
<div class="header">
<strong class="primary-font"><?php echo ($cruise_avatar[1]); ?></strong> <small class="pull-right text-muted">
<span class="glyphicon glyphicon-time"></span><?php echo date("h:i:s A"); ?></small>
</div>
<p>
<?php echo ($cruise_avatar[2]); ?>
</p>
</div>
</li>
<li class="right clearfix"><span class="chat-img pull-right">
<img src="http://placehold.it/50/FA6F57/fff&text=ME" alt="User Avatar" class="img-circle" />
</span>
<div class="chat-body clearfix">
<div class="header">
<small class=" text-muted"><span class="glyphicon glyphicon-time"></span><?php echo date("h:i:s A"); ?></small>
<strong class="pull-right primary-font">Bhaumik Patel</strong>
</div>
<p>
<?php echo ($cruise_avatar[2]); ?>
</p>
</div>
</li>
</ul>
</div>
<div class="panel-footer">
<div class="input-group">
<input id="btn-input" type="text" class="form-control input-sm" placeholder="Type your message here..." />
<span class="input-group-btn">
<button class="btn btn-warning btn-sm" id="btn-chat">
Send</button>
</span>
</div>
</div>
</div>
</div>
</div>
</section>
And that's it looks like this when clicked (view extern):
I tried to hide it with jQuery like this: UPDATE it to
<script>
$(document).ready(function(){
$(".bd-layoutbox-9").click(function(){
if ($("span.bd-icon-67.bd-icon").css("display","inline-block")){
$("span.bd-icon-67.bd-icon").css("display","none");
}
else if ($("span.bd-icon-67.bd-icon").css("display","none")){
$("span.bd-icon-67.bd-icon").css("display","inline-block");
}
});
});
</script>
and my span code
<div data-smooth-scroll data-animation-time="250" class=" bd-smoothscroll-3">
<span class="bd-icon-67 bd-icon "></span>
</div>
I can hide it when Chatbox is open, but when i close it is not displayed again.
I have a list of employees generated dynamically from database, and each employee has got an id, now I want to open a div box on each click with respect to the id's and display their id's in that box.
I am not able to access that div with respect to the id selected.
include 'connect.php';
$ert=mysql_query("Select * from login_session where bit='0' and date='$date'") or die(mysql_error());
while($we=mysql_fetch_array($ert)){
$employee_id=$we['employee_id'];
?>
<li> <?php echo $we['name'];?></li>
<div class="popup-box chat-popup" id="employee_<?php echo $employee_id; ?>">
<div class="popup-head">
<div class="popup-head-left pull-left"><img src="http://bootsnipp.com/img/avatars/bcf1c0d13e5500875fdd5a7e8ad9752ee16e7462.jpg" alt="iamgurdeeposahan"> Gurdeep Osahan
</div>
<div class="popup-head-right pull-right">
<div class="btn-group">
<button class="chat-header-button" data-toggle="dropdown" type="button" aria-expanded="false">
<i class="glyphicon glyphicon-cog"></i> </button>
<ul role="menu" class="dropdown-menu pull-right">
<li>Media</li>
<li>Block</li>
<li>Clear Chat</li>
<li>Email Chat</li>
</ul>
</div>
<button data-widget="remove" class="removeClass chat-header-button pull-right" type="button"><i class="glyphicon glyphicon-off"></i></button>
</div>
</div>
<div class="popup-messages">
<div class="direct-chat-messages">
<div class="chat-box-single-line">
<abbr class="timestamp">October 8th, 2015</abbr>
</div>
<!-- Message. Default to the left -->
<div class="direct-chat-msg doted-border">
<div class="direct-chat-info clearfix">
<span class="direct-chat-name pull-left">Osahan</span>
</div>
<!-- /.direct-chat-info -->
<img alt="message user image" src="http://bootsnipp.com/img/avatars/bcf1c0d13e5500875fdd5a7e8ad9752ee16e7462.jpg" class="direct-chat-img"><!-- /.direct-chat-img -->
<div class="direct-chat-text">
Hey bro, how’s everything going ?
</div>
<div class="direct-chat-info clearfix">
<span class="direct-chat-timestamp pull-right">3.36 PM</span>
</div>
<div class="direct-chat-info clearfix">
<span class="direct-chat-img-reply-small pull-left">
</span>
<span class="direct-chat-reply-name">Singh</span>
</div>
<!-- /.direct-chat-text -->
</div>
<!-- /.direct-chat-msg -->
<div class="chat-box-single-line">
<abbr class="timestamp">October 9th, 2015</abbr>
</div>
<!-- Message. Default to the left -->
<div class="direct-chat-msg doted-border">
<div class="direct-chat-info clearfix">
<span class="direct-chat-name pull-left">Osahan</span>
</div>
<!-- /.direct-chat-info -->
<img alt="iamgurdeeposahan" src="http://bootsnipp.com/img/avatars/bcf1c0d13e5500875fdd5a7e8ad9752ee16e7462.jpg" class="direct-chat-img"><!-- /.direct-chat-img -->
<div class="direct-chat-text">
Hey bro, how’s everything going ?
</div>
<div class="direct-chat-info clearfix">
<span class="direct-chat-timestamp pull-right">3.36 PM</span>
</div>
<div class="direct-chat-info clearfix">
<img alt="iamgurdeeposahan" src="http://bootsnipp.com/img/avatars/bcf1c0d13e5500875fdd5a7e8ad9752ee16e7462.jpg" class="direct-chat-img big-round">
<span class="direct-chat-reply-name">Singh</span>
</div>
<!-- /.direct-chat-text -->
</div>
</div>
</div>
<div class="popup-messages-footer">
<textarea id="status_message" placeholder="Type a message..." rows="10" cols="40" name="message"></textarea>
<div class="btn-footer">
<button class="bg_none"><i class="glyphicon glyphicon-film"></i> </button>
<button class="bg_none"><i class="glyphicon glyphicon-camera"></i> </button>
<button class="bg_none"><i class="glyphicon glyphicon-paperclip"></i> </button>
<button class="bg_none pull-right"><i class="glyphicon glyphicon-thumbs-up"></i> </button>
</div>
</div>
</div>
<script>
$(function(){
$(".addClass").click(function () {
var var1=$(this).data('employee');
$('#employee_'+var1).addClass('popup-box-on');
});
$(".removeClass").click(function () {
var var1=$(this).data('employee');
$('#employee_'+var1).removeClass('popup-box-on');
});
})
</script>
Firstly , inside the anchor tag <a> with class .addClass , you are using $we['employee_id'] and then for it's respective box you are using $employee_id which is null and it results to an undefined variable error.
You should give the trigger and target selectors a unqiue identifiers , such as for .addClass you can use data attributes for appending the data to target something. look below:
<?php echo $we['name'];?>
and then for respective box id you can assign a unique id to it something like:
<div class="popup-box chat-popup" id="employee_<?php echo $employee_id; ?>">
and at the end inside javascript / jquery , you can trigger them with the data attribute value and by placing the unique identifier we have created for target div. let say .addClass's data attribute contains 34, which is a employee id , and .popup-box will have id="employee_34" as we need to identify them with something unique and not only numbers.
$(function(){
$(".addClass").click(function () {
var var1=$(this).data('employee');
$('#employee_'+var1).addClass('popup-box-on');
});
});
at the end you php and html code should look like this:
include 'connect.php';
$ert=mysql_query("Select * from login_session where bit='0' and date='$date'") or die(mysql_error());
while($we=mysql_fetch_array($ert)){
?>
<li> <?php echo $we['name'];?></li>
<div class="popup-box chat-popup" id="employee_<?php echo $employee_id; ?>">
<div class="popup-head">
<div class="popup-head-left pull-left"><img src="http://bootsnipp.com/img/avatars/bcf1c0d13e5500875fdd5a7e8ad9752ee16e7462.jpg" alt="iamgurdeeposahan"> Gurdeep Osahan
</div>
<div class="popup-head-right pull-right">
<div class="btn-group">
<button class="chat-header-button" data-toggle="dropdown" type="button" aria-expanded="false">
<i class="glyphicon glyphicon-cog"></i> </button>
<ul role="menu" class="dropdown-menu pull-right">
<li>Media</li>
<li>Block</li>
<li>Clear Chat</li>
<li>Email Chat</li>
</ul>
</div>
<button data-widget="remove" id="removeClass" class="chat-header-button pull-right" type="button"><i class="glyphicon glyphicon-off"></i></button>
</div>
</div>
<div class="popup-messages">
<div class="direct-chat-messages">
<div class="chat-box-single-line">
<abbr class="timestamp">October 8th, 2015</abbr>
</div>
<!-- Message. Default to the left -->
<div class="direct-chat-msg doted-border">
<div class="direct-chat-info clearfix">
<span class="direct-chat-name pull-left">Osahan</span>
</div>
<!-- /.direct-chat-info -->
<img alt="message user image" src="http://bootsnipp.com/img/avatars/bcf1c0d13e5500875fdd5a7e8ad9752ee16e7462.jpg" class="direct-chat-img"><!-- /.direct-chat-img -->
<div class="direct-chat-text">
Hey bro, how’s everything going ?
</div>
<div class="direct-chat-info clearfix">
<span class="direct-chat-timestamp pull-right">3.36 PM</span>
</div>
<div class="direct-chat-info clearfix">
<span class="direct-chat-img-reply-small pull-left">
</span>
<span class="direct-chat-reply-name">Singh</span>
</div>
<!-- /.direct-chat-text -->
</div>
<!-- /.direct-chat-msg -->
<div class="chat-box-single-line">
<abbr class="timestamp">October 9th, 2015</abbr>
</div>
<!-- Message. Default to the left -->
<div class="direct-chat-msg doted-border">
<div class="direct-chat-info clearfix">
<span class="direct-chat-name pull-left">Osahan</span>
</div>
<!-- /.direct-chat-info -->
<img alt="iamgurdeeposahan" src="http://bootsnipp.com/img/avatars/bcf1c0d13e5500875fdd5a7e8ad9752ee16e7462.jpg" class="direct-chat-img"><!-- /.direct-chat-img -->
<div class="direct-chat-text">
Hey bro, how’s everything going ?
</div>
<div class="direct-chat-info clearfix">
<span class="direct-chat-timestamp pull-right">3.36 PM</span>
</div>
<div class="direct-chat-info clearfix">
<img alt="iamgurdeeposahan" src="http://bootsnipp.com/img/avatars/bcf1c0d13e5500875fdd5a7e8ad9752ee16e7462.jpg" class="direct-chat-img big-round">
<span class="direct-chat-reply-name">Singh</span>
</div>
<!-- /.direct-chat-text -->
</div>
</div>
</div>
<div class="popup-messages-footer">
<textarea id="status_message" placeholder="Type a message..." rows="10" cols="40" name="message"></textarea>
<div class="btn-footer">
<button class="bg_none"><i class="glyphicon glyphicon-film"></i> </button>
<button class="bg_none"><i class="glyphicon glyphicon-camera"></i> </button>
<button class="bg_none"><i class="glyphicon glyphicon-paperclip"></i> </button>
<button class="bg_none pull-right"><i class="glyphicon glyphicon-thumbs-up"></i> </button>
</div>
</div>
</div>
<?php } ?>
and your javascript code like below:
$(function(){
$(".addClass").click(function () {
var var1=$(this).data('employee');
$('#employee_'+var1).addClass('popup-box-on');
});
});
and do in this way same for removing the respective box for employee div.
Note
As the popup-box div's are multiple and are already inside the dom , you should not use id selector for remove trigger , as it will target only first div and not others , use an class for removing the div as well such as removeBox
Update for remove
For removing the div, don't use id for removing the div , change your remove button to the following:
<button data-widget="remove" data-employee="<?php echo $we['employee_id']; ?>" class="chat-header-button removeClass pull-right" type="button"><i class="glyphicon glyphicon-off "></i></button>
and use the below jquery code for removing the div
$(function(){
$(".removeClass").click(function () {
var var1=$(this).data('employee');
$('#employee_'+var1).removeClass('popup-box-on');
});
});
This is the code about in my template file
<ul class="playListForm" id="playList" style="list-style: none;">
#foreach($listSong as $song)
<!--<?php
$url = URL::route("listentomusic",$song->id_song."**".$song->title."**".$song->artist."**".$song->code128."**".$song->code320);
$urlup = URL::route("voteup", $song->id_song);
$urldown = URL::route("votedown", $song->id_song);
?>-->
<?php
$urlsource = 'http://api.mp3.zing.vn/api/mobile/source/song/'.$song->code128;
if($song->position == 1){
?>
<li id="{{$song->position}}" class="active">
<div class="form-inline plItem">
<div class="form-group plNum">{{$song->position}}</div>
<a id="songURL" href="{{$urlsource}}"><div id="songInfo" class="form-group plTitle" value="{{$song->title}} - {{$song->artist}}">{{$song->title}} - {{$song->artist}}</div>
</a>
<div class="form-group">
<div class="form-inline">
<p style="display:none" id="songId">{{$song->id_song}}</p>
<button id="upBtn" class="form-group btn btn-default btnUp" style="visibility: hidden;">
Up
</button>
<button id="dwnBtn" class="form-group btn btn-default btnDown">
Down
</button>
</div>
</div>
<hr style="margin-top: 9px">
</div>
</li>
<?php
}
else{
if($song->position != count($listSong)){
?>
<li id="{{$song->position}}">
<div class="form-inline plItem">
<div class="form-group plNum">{{$song->position}}</div>
<a id="songURL" href="{{$urlsource}}"><div id="songInfo" class="form-group plTitle" value="{{$song->title}} - {{$song->artist}}">{{$song->title}} - {{$song->artist}}</div></a>
<div class="form-group">
<div class="form-inline">
<p style="display:none" id="songId">{{$song->id_song}}</p>
<button id="upBtn" class="form-group btn btn-default btnUp">
Up
</button>
<button id="dwnBtn" class="form-group btn btn-default btnDown">
Down
</button>
</div>
</div>
<hr style="margin-top: 10px">
</div>
</li>
<?php
}
else{
?>
<li id="{{$song->position}}">
<div class="form-inline plItem">
<div class="form-group plNum">{{$song->position}}</div>
<a id="songURL" href="{{$urlsource}}"><div id="songInfo" class="form-group plTitle" value="{{$song->title}} - {{$song->artist}}">{{$song->title}} - {{$song->artist}}</div></a>
<div class="form-group">
<div class="form-inline">
<p style="display:none" id="songId">{{$song->id_song}}</p>
<button id="upBtn" class="form-group btn btn-default btnUp">
Up
</button>
<button id="dwnBtn" class="form-group btn btn-default btnDown" style="visibility: hidden;">
Down
</button>
</div>
</div>
<hr style="margin-top: 10px">
</div>
</li>
<?php
}
}
?>
#endforeach
</ul>
And I tried to append new "li" by this JQuery code:
var newLI = '<li id="'+lastPos+'">'+
'<div class="form-inline plItem">'+
'<div class="form-group plNum">'+lastPos+'</div>'+
'<a id="songURL" href="'+'http://api.mp3.zing.vn/api/mobile/source/song/'+song['code128']+'"><div id="songInfo" class="form-group plTitle" value="'+song['title']+' - '+song['artist']+'">'+song['title']+' - '+song['artist']+'</div></a>'+
'<div class="form-group">'+
'<div class="form-inline">'+
'<p style="display:none" id="songId">'+song['id_song']+'</p>'+
'<button id="upBtn" class="form-group btn btn-default btnUp">'+
'Up'+
'</button>'+
'<button id="dwnBtn" class="form-group btn btn-default btnDown" style="visibility: hidden;">'+
'Down'+
'</button>'+
'</div>'+
'</div>'+
'<hr style="margin-top: 10px">'+
'</div>'+
'</li>';
$('#playList').append(''+newLI+'');
And here is the result:
So I have a problem about the new li at the last which I added by JQuery. I really don't know why. I hope you could give me some advices. Thank you.
P/S: Sorry for my bad English.
Same id maybe confused, generate with function
function generate(lastPos){
var newLI = '<li id="'+lastPos+'">'+
'<div class="form-inline plItem">'+
'<div class="form-group plNum">'+lastPos+'</div>'+
'<a id="songURL" href="'+'http://api.mp3.zing.vn/api/mobile/source/song/'+song['code128']+'"><div id="songInfo" class="form-group plTitle" value="'+song['title']+' - '+song['artist']+'">'+song['title']+' - '+song['artist']+'</div></a>'+
'<div class="form-group">'+
'<div class="form-inline">'+
'<p style="display:none" id="songId">'+song['id_song']+'</p>'+
'<button id="'+lastPos+'_upBtn" class="form-group btn btn-default btnUp">'+
'Up'+
'</button>'+
'<button id="'+lastPos+'_dwnBtn" class="form-group btn btn-default btnDown" style="visibility: hidden;">'+
'Down'+
'</button>'+
'</div>'+
'</div>'+
'<hr style="margin-top: 10px">'+
'</div>'+
'</li>';
$('#playList').append(''+newLI+'');
}
call function and new id for LI Element.