This is continuation of my question first question
Here i am drag and drop sticky notes from one to another. i have
<div class="rTable">
<div class="rTableRow">
<div id="a" title="Backog" class="rTableHead rTabletd"><strong>Backlog</strong></div>
<div id="a" title="WIP" class="rTableHead rTabletd"><span style="font-weight: bold;">WIP</span></div>
<div id="a" title="Testing" class="rTableHead rTabletd">Testing</div>
<div id="a" title="DOD" class="rTableHead rTabletd">DOD</div>
</div>
<div class="rTableRow rTableh" >
<div class="rTableCell"></div>
<div class="rTableCell"><a></a></div>
<div class="rTableCell"></div>
<div class="rTableCell"></div>
</div>
</div>
and sticky notes
<?php
foreach ($this->getallstores as $stories):
?>
<div id="draggable-<?php echo $stories['id']; ?>" class="draggable " onchange="javascript:position(this)" style="position:absolute; left: <?php echo $stories['_left']; ?>px; top: <?php echo $stories['_top']; ?>px">
<img class="pin" src="/manage/public/img/pin.png" alt="pin" />
<blockquote class="quote-box note-<?php echo $stories['color']; ?>">
<p class="quote-text" id="content-<?php echo $stories['id'];?>">
<?php echo $stories['message']; ?>
</p>
<hr>
<div class="blog-post-actions">
<p>
<button class="btn btn-primary popEdit pull-left" data-toggle='tooltip' title="Edit" onClick="popOverEdit(<?php echo $stories['id'];?>)" id="pop-<?php echo $stories['id'];?>"><span class="glyphicon glyphicon-edit"></span></button>
<div class="popover-markup blog-post-bottom" >
<div class="head hide">Edit</div>
<div class="content hide" id="popoverContent<?php echo $stories['id'];?>">
<div class="form-group">
<textarea id="<?php echo $stories['id']; ?>" class="quick" ><?php echo $stories['message']; ?></textarea>
</div>
<button data-vendor-id="" data-act="send" onClick="getText(<?php echo $stories['id'];?>)" class="btn btn-info save_notes">Save</button>
</div>
</div>
</p>
<p class="blog-post-bottom pull-right">
<a class="delete" href="?delete=<?php echo $stories['id']; ?>" style="float:right"> <button class="btn btn-danger" title="delete"><span class="glyphicon glyphicon-trash"></span></button> </a>
</p>
</div>
</blockquote>
</div>
<?php endforeach;?>
demo
my requirement is i want to drag and drop stickys and save to database.Now i have save position.is there any way to save column name?eg if drag sticky note from backlog to testing how can i get placed position name is testing?Please help me.
jquery
jQuery(function() {
jQuery( ".draggable" ).draggable({ containment: "#containment-wrapper", scroll: false ,
// Find position where image is dropped.
stop: function(event, ui) {
// Show dropped position.
var id=$(this).attr('id');
var ti=$(".rTabletd").attr("title");
var Stoppos = $(this).position();
model = {
id:id,
left: Stoppos.left,
top: Stoppos.top
};
$.ajax({
url: "/scrum/save",
type: "post",
data: model,
success: function(data){
jQuery.HP({
title: "Success!",
message: "Saved..."
});
},
error:function(){
// alert('error is saving');
}
});
}
});
});
You can create an array and use the droppable index position to select the array value.
var table = ['Backlog', 'WIP', 'Testing', 'DOD'];
$(".rTableCell > div").draggable();
$(".rTableCell").droppable({
drop: function(event, ui) {
var table = ['Backlog', 'WIP', 'Testing', 'DOD'];
var droppedOn = event.target;
alert(table[$(droppedOn).index()]);
}
});
.rTableHead,
.rTableCell {
display: inline-block;
width: 23%;
}
.rTableCell {
border: 1px solid black;
height: 100vh;
}
.rTableCell>div {
background-color: blue;
padding: 5px;
color: white;
border-radius: 5px;
margin: 5px;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<div class="rTable">
<div class="rTableRow">
<div id="backlog" title="Backog" class="rTableHead rTabletd"><strong>Backlog</strong></div>
<div id="WIP" title="WIP" class="rTableHead rTabletd"><span style="font-weight: bold;">WIP</span></div>
<div id="TESTING" title="Testing" class="rTableHead rTabletd"><span style="font-weight: bold;">Testing</span></div>
<div id="DOD" title="DOD" class="rTableHead rTabletd"><span style="font-weight: bold;">DOD</span></div>
</div>
<div class="rTableRow rTableh">
<div class="rTableCell">
<div>
Item 1
</div>
</div>
<div class="rTableCell">
<div>
Item 2
</div>
</div>
<div class="rTableCell">
<div>
Item 3
</div>
</div>
<div class="rTableCell">
<div>
Item 4
</div>
</div>
</div>
</div>
Related
This question already has answers here:
Using the context of the 'this' keyword with jQuery
(4 answers)
jQuery $(this) keyword
(6 answers)
Closed 3 years ago.
I am working on PHP to display a modal when I click on a hyperlink. I have got a problem with post the ID in ajax, because it will not fetch the id from the hyperlink to post it in ajax so I don't know why.
I have tried this but it didnt work:
var id = $(this).attr('autoid');
$.ajax({
type: 'POST',
url: "sendtest.php",
data: {autoid : id},
success: function(resultData)
{
alert(resultData)
}
here is the code:
<span style="font-size: 15px; color: #ccd5d9; float: left; margin-top: -1px">Send a test | <a name="autoid" id="autoid" href="/delete_id.php?id=<?php echo $autoid ?>"> Delete </a> | Copy to Draft | Settings</span>
<div id="contactModal" class="modal fade" style="margin-top: 12%;" tabindex="-1" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content" style="height: 250px;">
<div class="modal-header" style="margin-bottom: 10px;">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 class="modal-title">Send A Test Email</h3>
</div>
<div class="modal-body" style="height: 65%;">
<form action="" method="post">
<label class="label-control" value="">Send test message to email address:</label>
<?php
$html = '<select name="emails" id="emails" value="" style="width: 400px; margin-top: 10px; margin-bottom: 18px; margin-left: 60px;">';
$values = array('unknown', $_SESSION["email"]);
foreach($values as $v)
{
$selected = '';
if($v == 'unknown')
{
$title = '';
}else{
$title = $v;
}
if($v == $_SESSION["from"])
{
$selected = "selected";
}
$html .= "<option $selected value='$v'>$title</option>";
}
$html .= "
</select><br>";
echo $html;
?>
<button name="send_email" id="send_email" type="submit" class="btn btn-primary" style="margin-left: 36%;">Send Test</button>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$('#send_email').click(function(){
document.getElementById("send_email").innerHTML = "<span><i class=\'fa fa-spinner fa-spin\'></i> Sending...</span>";
document.getElementById('send_email').disabled = true;
var id = $(this).attr('autoid');
alert( $(this).attr('autoid'));
$.ajax({
type: 'POST',
url: "sendtest.php",
data: {autoid : id},
success: function(resultData)
{
alert(resultData)
$('#contactModal').modal('hide');
document.getElementById("send_email").innerHTML = "Send Test";
document.getElementById('send_email').disabled = false;
}
});
});
</script>
in sendtest.php:
<?php
// Initialize the session
session_start();
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
else if(isset($_POST))
{
$param_username = $_SESSION['username'];
$param_campaign = $_SESSION['campaign'];
$id = $_POST['autocampaign'];
echo "hello your id is...";
echo $id;
}
?>
I'm sorry if it have been posted very similar in the past, but this is a difficult situation I have been going through so I would like to get some help with this.
So what I am trying to do is when I click on a button to display on a modal and select a value, I click on a button again to get the ID autoid to post it via ajax and display the alert with the ID.
Can you please show me an example what is the correct way I could use to fetch the ID from the HTML tag called autoid so I can post it in ajax to display the ID in the alert?
Thank you.
EDIT: It didn't work when I try this:
<form action="" method="post">
<span style="font-size: 15px; color: #ccd5d9; float: left; margin-top: -1px"><a name="autoid" id="autoid" href="#contactModal" role="button" data-toggle="modal">Send a test</a> | <a name="autoid" id="autoid" href="/delete_id.php?id=<?php echo $autoid ?>"> Delete </a> | Copy to Draft | Settings</span>
</form>
in sendtest.php:
<?php
// Initialize the session
session_start();
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
else if(isset($_POST))
{
$param_username = $_SESSION['username'];
$param_campaign = $_SESSION['campaign'];
$id = $_POST['autoid'];
echo "hello your id is...";
echo $id;
}
?>
At all I get is hello your id is... in the alert.
UPDATE: Here is the full code:
<?php
// Initialize the session
session_start();
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
else
{
$link = mysqli_connect('localhost', 'mydbusername', 'mydbpassword', 'mydbname');
$param_username = $_SESSION['username'];
$autocampaign = $_SESSION["campaign"];
$auto_sql = "SELECT id, subject, day_cycle, enabled, delaysend FROM autore WHERE campaign ='$autocampaign' AND username ='$param_username'";
$results = mysqli_query($link, $auto_sql);
if (mysqli_num_rows($results) > 0)
{
while ($row = mysqli_fetch_array($results))
{
$autoid = $row["id"];
$autosubject = $row["subject"];
$autodaycycle = $row["day_cycle"];
$autoenabled = $row["enabled"];
$autodelay = $row["delaysend"];
}
}
?>
<!DOCTYPE html>
<html>
<head>
<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/1.12.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style type="text/css">
.calendar-content {
float: left;
width: 100%;
min-height: 112px;
border: 1px solid #ccc;
position: relative;
margin-top: -1px;
}
</style>
<div class="calendar-content">
<div style="margin-left: 40px;margin-top: 20px; height: 40px;">
<span id="autosubject" style="font-size: 25px;color: #0c7ac0;float: left;">Subject: <?php echo $autosubject ?> </span><br>
<div style="margin-left: 35px; margin-top: 15px; height: 40px;">
<form action="" method="post">
<span style="font-size: 15px; color: #ccd5d9; float: left; margin-top: -1px"><a name="autoid" id="autoid" href="#contactModal" role="button" data-toggle="modal">Send a test</a> | <a name="deleteid" id="deleteid" href="/delete_id.php?id=<?php echo $autoid; ?>"> Delete </a> | Copy to Draft | Settings</span>
</form>
</div>
</div><br>
<!-- email Modal -->
<div id="contactModal" class="modal fade" style="margin-top: 12%;" tabindex="-1" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content" style="height: 250px;">
<div class="modal-header" style="margin-bottom: 10px;">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 class="modal-title">Send A Test Email</h3>
</div>
<div class="modal-body" style="height: 65%;">
<form action="" method="post">
<label class="label-control" value="">Send test message to email address:</label>
<select name="emails" id="emails" value="" style="width: 400px; margin-top: 10px; margin-bottom: 18px; margin-left: 60px;">
<option selected="selected" value='title'>Title</option>";
</select><br>
<button name="send_email" id="send_email" type="submit" class="btn btn-primary" style="margin-left: 36%;" data-auto-id="<?php echo $autoid; ?>">Send Test</button>
</form>
</div>
</div>
</div>
</div>
<?php
}
?>
<script type="text/javascript">
$(function() {
$('#send_email').click(function(e) {
$(this)
.html("<span><i class='fa fa-spinner fa-spin'></i> Sending...</span>")
.prop("disabled", true);
var id = $(this).data('deleteid');
$.ajax({
type: 'POST',
url: "sendtest.php",
data: {
deleteid: id
},
success: function(resultData) {
alert(resultData)
$('#contactModal').modal('hide');
$("#send_email")
.html("Send Test")
.prop("disabled", false);
}
});
});
});
</script>
</body>
</html>
In your sendtest.php you will want to change:
$id = $_POST['autocampaign'];
To the following:
$id = $_POST['autoid'];
Hope that helps.
Updated
var id = $(this).attr('autoid'); will fail since $(this) is a refernce to the Button Object and not the form. The <button> also does not have an attribute called autoid. Therefore, id will be null or undefined.
Where should id get it's value from?
$(function() {
$('#send_email').click(function(e) {
$(this)
.html("<span><i class='fa fa-spinner fa-spin'></i> Sending...</span>")
.prop("disabled", true);
var id = $(this).data('auto-id');
$.ajax({
type: 'POST',
url: "sendtest.php",
data: {
autoid: id
},
success: function(resultData) {
alert(resultData)
$('#contactModal').modal('hide');
$("#send_email")
.html("Send Test")
.prop("disabled", false);
}
});
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="calendar-content">
<div style="margin-left: 40px;margin-top: 20px; height: 40px;">
<span id="autosubject" style="font-size: 25px;color: #0c7ac0;float: left;">Subject: <?php echo $autosubject ?> </span><br>
<div style="margin-left: 35px; margin-top: 15px; height: 40px;">
<form action="" method="post">
<span style="font-size: 15px; color: #ccd5d9; float: left; margin-top: -1px"><a name="autoid" id="autoid" href="#contactModal" role="button" data-toggle="modal">Send a test</a> | <a name="autoid" id="autoid" href="/autoresponder/delete_autoresponder.php?id=<?php echo $autoid; ?>"> Delete </a> | Copy to Draft | Settings</span>
</form>
</div>
</div><br>
<!-- email Modal -->
<div id="contactModal" class="modal fade" style="margin-top: 12%;" tabindex="-1" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content" style="height: 250px;">
<div class="modal-header" style="margin-bottom: 10px;">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 class="modal-title">Send A Test Email</h3>
</div>
<div class="modal-body" style="height: 65%;">
<form action="" method="post">
<label class="label-control" value="">Send test message to email address:</label>
<select name="emails" id="emails" value="" style="width: 400px; margin-top: 10px; margin-bottom: 18px; margin-left: 60px;">
<option selected="selected" value='title'>Title</option>";
</select><br>
<button name="send_email" id="send_email" type="submit" class="btn btn-primary" style="margin-left: 36%;" data-auto-id="<?php echo $autoid; ?>">Send Test</button>
</form>
</div>
</div>
</div>
</div>
The following code is cleaned up. First, I added the data-auto-id attribute that contains the autoid from PHP. This can then be read and passed into the AJAX.
Also switched into all jQuery for consistency.
I want to delete user with bootbox dialog window but when i click remove button the bootbox dialog window doesn't show. I wrote a simple program. Here is my codes:
Before i confirm in libraries:
<head>
<title>Adminstration</title>
<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.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="bootbox.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
My html code like this:
<form id="form1" action="footer.php">
<div class="body-wrap" id="wrapper" style="overflow: auto;">
<div class="container" id="container" style=" margin-top: 40px;">
<div class="well col-xs-8 col-sm-8 col-md-8 col-lg-8 col-xs-offset-2 col-sm-offset-2 col-md-offset-2 col-lg-offset-2" id="well">
<?php $arr = array(1, 2, 3, 4); foreach ($arr as $value)
{ $value = $value * 2;
?>
<div class="row user-row" style="border-bottom: 1px solid #ddd;">
<div class="col-xs-8 col-sm-9 col-md-10 col-lg-10">
<strong><?php echo $value ?></strong><br>
<span class="text-muted">Value: <?php echo $value; ?> </span>
</div>
<div class="col-xs-1 col-sm-1 col-md-1 col-lg-1 dropdown-user pull-right" data-for=".<?php echo $value; ?>">
<i class="glyphicon glyphicon-chevron-down text-muted "></i>
</div>
</div>
<div class="row user-infos <?php echo $value; ?>" id="user-infos">
<div class="col-xs-12 col-sm-12 col-md-10 col-lg-10 col-xs-offset-0 col-sm-offset-0 col-md-offset-1 col-lg-offset-1" id="col-xs">
<div class="panel panel-primary" id="panel">
<div class="panel-heading">
<h2 class="panel-title" style="text-align: center;">user info</h2>
</div>
<div class="panel-body">
<div class="row-fluid">
<div class="span6">
<h3> <?php echo $value ?> </h3><br>
</div>
</div>
</div>
<div class="panel-footer clearfix" id="footer">
<span>
<a class="delete_user btn btn-danger btn-sm pull-right" id="del" href="" data-toggle="tooltip" title="Delete user"><span class="glyphicon glyphicon-remove"></span></a>
</span >
</div>
</div>
</div>
</div><?php } ?>
</div>
</div>
</div>
</form>
And js code:
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
/************************USERS********************************/
$(document).ready(function() {
var panels = $('.user-infos');
var panelsButton = $('.dropdown-user');
panels.hide();
//Click dropdown
panelsButton.click(function() {
//get data-for attribute
var dataFor = $(this).attr('data-for');
var idFor = $(dataFor);
//current button
var currentButton = $(this);
idFor.slideToggle(400, function() {
//Completed slidetoggle
if(idFor.is(':visible'))
{
currentButton.html('<i class="glyphicon glyphicon-chevron-up text-muted"></i>');
}
else
{
currentButton.html('<i class="glyphicon glyphicon-chevron-down text-muted"></i>');
}
})
});
});
/********************************************************/
/************************DELETE USERS*************************************/
$(document).ready(function(){
$('.delete_user#del').click(function(e){
e.preventDefault();
bootbox.dialog({
message: "<i class='fa fa-warning fa-2x' style='color: orange;'></i><span style='font-size:16px; position: absolute; margin-left: 5px; margin-top: 5px;'>Are you sure to delete this user?</span>",
title: "<i class='glyphicon glyphicon-trash'></i> Delete user!",
buttons: {
danger: {
label: "Delete!",
className: "btn-danger",
callback: function() {/*some code*/}
},
success: {
label: "No",
className: "btn-success",
callback: function() {
$('.bootbox').modal('hide');
}
}
}
});
});
});
/*******************************************************************/
This js code for bootbox dialog is work another php file but doesn't work for this php file.
Sorry, I have found lots of answers here regarding modals and jQuery, but I cant find anything that helps me. I have a form that has photos. People should be able to click on the photo and it would open a larger version in a modal window. For the life of me, I can't figure out how to pass the value of the photo name to the modal. Here is what I have:
php/HTML:
<?php
$imgno = 1;
$dir = "memberphotos/$id/";
$qry = "SELECT PhotoName, Visible, Likes FROM photolist WHERE UserID = " . $id;
if ($result = mysqli_query($GLOBALS['link'], $qry)) {
while ($row = $result->fetch_assoc()) {
?>
<div class="col-md-3 col-sm-4 col-xs-6">
<div class="album-image">
<a href="#" class="thumb" data-action="edit" src='<?php $dir.$row['PhotoName']; ?>'>
<img src="<?php echo $dir . $row['PhotoName'] . "_thumb.jpg"; ?>"
class="img-responsive"/>
</a>
<a href="#" class="name">
<i class="fa-heart-o"> <?php if (!empty($row['Likes'])) {echo $row['Likes']." Likes";} ?> </i>
</a>
<div class="image-options">
<i class="fa-heart-o"></i>
</div>
</div>
</div>
<?php
$imgno = $imgno+1;}
}
?>
Now for the jquery:
<script type="text/javascript">
// Sample Javascript code for this page
jQuery(document).ready(function ($) {
// Edit Modal
$('.gallery-env a[data-action="edit"]').on('click', function (ev) {
var id = ('data-id');
ev.preventDefault();
$("#gallery-image-modal").modal('show');
});
});
</script>
Now, the code... I hard coded an image name into the img src to make sure it works, which it does. I'm just trying to get the photo name from the database, stored for each photo and passed to the modal.
<div class="modal fade" id="gallery-image-modal" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-gallery-image">
<img src="<?php echo $dir . '2017-02-28_1_B828A.jpg'; ?>" class="img-responsive"/>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<a href="#" class="name">
<i class="fa-heart"> <?php echo $row['Likes']; ?> Likes</i>
</a>
</div>
</div>
</div>
<?php if ($id == $_SESSION['uid']) {?>
<div class="modal-footer modal-gallery-top-controls">
<button type="button" class="btn btn-xs btn-white" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-xs btn-info">Set as Main</button>
<button type="button" class="btn btn-xs btn-red">Delete image</button>
</div>
<?php } ?>
</div>
</div>
</div>
I can't figure this out... a little help for a humble learning coder?
Using .on() events isn't always the best solution. You also don't need to wrap the image inside of an a tag.
<img src="<?php echo $dir . $row['PhotoName'] . "_thumb.jpg"; ?> onclick="openImgModal('<?php echo $dir . $row['PhotoName']; ?>')" class="img-responsive"/>
Javascript:
function openImgModal(img_src)
{
$('.modal-gallery-image').html('<img src="'+img_src+'" class="img-responsive" />');
$("#gallery-image-modal").modal('show');
}
maybe add some CSS to indicate the image is clickable
.img-responsive
{
cursor: pointer;
}
Here is an easy way that does not include inline javascript
HTML
<div class="cover"> </div>
<div class="modalPhoto">
<img src="" />
</div>
CSS (can adjust this for your needs)
.cover {
position:fixed;
top:0;
left:0;
background:rgba(0,0,0,0.6);
z-index:9997;
width:100%;
height:100%;
display:none;
}
body.open .cover {
display:block;
}
.modalPhoto {
position:fixed;
z-index:9998;
width:680px;
height:550px;
background:#fff;
text-align:center;
box-shadow:0 0 15px -5px rgba(0,0,0,0.8);
top:50%;
margin-top:-1500px;
left:50%;
margin-left:-350px;
-webkit-transition:800ms margin-top ease-in-out;
transition:800ms margin-top ease-in-out;
overflow:hidden;
border:10px solid #fff;
}
body.open .modalPhoto {
margin-top:-285px;
}
jQuery
$('.gallery-env a img').on('click', function(e) {
var photo = $(this).data('src');
$('.modalPhoto').find('img').attr('src', photo);
$('body').addClass('open');
});
$('.cover').on('click',function() {
$('body').removeClass('open');
});
Let me know if any of this doesn't make sense
I want to do PG booking, I have one form field in that field(index.php) i select room sharing like 1 sharing or 2 sharing etc...after select this pg sharing i passed the value in next page(pg_deatils.php) through AJAX and i select from DB which room are having 1 sharing or 2 sharing after i return the value in index.php still i am getting correct after that i want append the value in html,insteed of Room 1,Romm 2... i want append the value of console.log(value.pg_id);// 2,1 and insteed of Bed 1,Bed1...i want to append console.log(value.room_number);//room1,room2
function showDiv(toggle){
var sharing=$("#sharing").val();
$.ajax({
type: "POST",
url: "pg_details.php",
data: "sharing_id="+sharing,
success: function(data) {
var res =jQuery.parseJSON(data);
console.log(res);
if(res['return'] == 1){
var htmlString='';
$.each( res['data'], function( key, value ){
console.log(value.pg_id);// 2,1
console.log(value.room_number);//room1,room2
});
}
}
});
}
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<h3 style="text-align:center;color:white; margin-top:70px;padding-bottom:30px;">PG Booking System</h3>
<form class="form-horizontal" >
<div class="form-group">
<label class="control-label col-sm-2" for="phone">Sharing:</label>
<div class="col-sm-10">
<select class="form-control" name="sharing" id="sharing">
<option value="">---select---</option>
</select>
</div>
</div>
<div class="form-group" style="margin-top:30px;">
<div class="col-sm-offset-5 col-sm-8">
<button type="button" class="btn btn-primary" name="answer" onclick="showDiv('toggle')" style=" margin-top:50px;margin-bottom:50px;">Submit</button>
</div>
</div>
</form>
</div>
<div class="col-md-3"></div>
</div>
<!--This HTML i want to append-->
<div id="toggle" style="display:none">
<div class="container" style=" margin-bottom: 30px;">
<div class="row">
<h4 style="margin-left:15px;">PG NAME 1</h4>
<div class="col-sm-10">
<div class="btn-group" id="btnmar">
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px; ">Bed 1</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 2</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px; ">Bed 3</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px; ">Bed 4</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 5</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px; ">Bed 6</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 7</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 8</button>
</a>
</div>
</div>
<!--hidden 6 end-->
<!--hidden 4 start-->
<div class="col-sm-2">
<div class="panel-group">
<div class="panel panel-primary">
<div class="panel-heading"> Premium Facility</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-television" aria-hidden="true" style="margin-right:15px;"></i>T.V.</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-wifi" aria-hidden="true" style="margin-right:15px;"></i>Wifi</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-bed" aria-hidden="true" style="margin-right:15px;"></i>Bed</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-shopping-basket" aria-hidden="true" style="margin-right:15px;"></i>Washing Machine</div>
</div>
</div>
</div>
<!--hidden 4 end-->
</div>
<!--row1 end-->
<!--row2 start-->
<div class="row">
<h4 style="margin-left:15px;">PG NAME 2</h4>
<div class="col-sm-10">
<div class="btn-group" id="btnmar">
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 1</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 2</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 3</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 4</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 5</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 6</button>
</a>
</div>
</div>
<!--hidden 6 end-->
<!--hidden 4 start-->
<div class="col-sm-2">
<div class="panel-group">
<div class="panel panel-primary">
<div class="panel-heading"> Classic Facility</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-television" aria-hidden="true" style="margin-right:15px;"></i>T.V.</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-wifi" aria-hidden="true" style="margin-right:15px;"></i>Wifi</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-bed" aria-hidden="true" style="margin-right:15px;"></i>Bed</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-shopping-basket" aria-hidden="true" style="margin-right:15px;"></i>Washing Machine</div>
</div>
</div>
</div>
<!--hidden 4 end-->
</div>
<!--row2 end-->
<!--row2 start-->
<div class="row">
<h4 style="margin-left:15px;">PG NAME 3</h4>
<div class="col-sm-10">
<div class="btn-group" id="btnmar">
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 1</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 2</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 3</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 4</button>
</a>
<a href="register.php">
<button type="button" class="btn btn-primary" style=" width: 71px;">Bed 5</button>
</a>
</div>
</div>
<!--hidden 6 end-->
<!--hidden 4 start-->
<div class="col-sm-2">
<div class="panel-group">
<div class="panel panel-primary">
<div class="panel-heading"> Basic Facility</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-television" aria-hidden="true" style="margin-right:15px;"></i>T.V.</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-wifi" aria-hidden="true" style="margin-right:15px;"></i>Wifi</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-bed" aria-hidden="true" style="margin-right:15px;"></i>Bed</div>
<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-shopping-basket" aria-hidden="true" style="margin-right:15px;"></i>Washing Machine</div>
</div>
</div>
</div>
<!--hidden 4 end-->
</div>
<!--row3 end-->
</div>
</div>
pg_details.php
<?php
include_once("admin/config.php");
include("functions.php");
//$pg_name=Getpg($_POST['pg_id']);
$sharing=$_POST['sharing_id'];//Getting Sharing Value
$sql=mysql_query("SELECT * FROM rooms WHERE room_sharing='$sharing'");
$count = mysql_num_rows($sql);
if($count > 0){
while($row=mysql_fetch_assoc($sql)){
$data[]= $row;
}
$pg_type= array("return"=>1,"count" =>$count,"data" =>$data);
echo $pg_type = json_encode($pg_type);
}else{
$pg_type= array("return"=>0,"count" =>0,"data" =>"");
echo $pg_type = json_encode($pg_type);
}
?>
I assumed certain data from your database table and created this. You will have to tweak it all a little to get it according to your data.
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<h3 style="text-align:center;color:white; margin-top:70px;padding-bottom:30px;">PG Booking System</h3>
<form class="form-horizontal" >
<div class="form-group">
<label class="control-label col-sm-2" for="phone">Sharing:</label>
<div class="col-sm-10">
<select class="form-control" name="sharing" id="sharing">
<option value="">---select---</option>
<!-- <?php
$sql = "SELECT * FROM sharing";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo '<option value="'.$row["id"].'">'.$row["sharing_type"].'</option>';
}
?>-->
<option value='1'>one</option>
<option value='2'>two</option>
<option value='3'>three</option>
</select>
</div>
</div>
<div class="form-group" style="margin-top:30px;">
<div class="col-sm-offset-5 col-sm-8">
<button type="button" class="btn btn-primary" name="answer" onclick="showDiv('toggle')" style=" margin-top:50px;margin-bottom:50px;">Submit</button>
</div>
</div>
</form>
</div>
<div class="col-md-3"></div>
</div>
//////This HTML i want to append
<div id="toggle" style="display:none">
<div class="container" id='pgDetails' style=" margin-bottom: 30px;">
</div>
</div>
<script>
function showDiv(toggle){
var sharing=$("#sharing").val();
$.ajax({
type: "POST",
url: "pg_details.php",
data: "sharing_id="+sharing,
success: function(data) {
var res =jQuery.parseJSON(data);
console.log(res);
if(res['return'] == 1){
$( "#toggle" ).show();
var htmlString='';
$.each( res['data'], function( key, value ){
console.log(value.pg_id);// 2,1
console.log(value.room_number);//room1,room2
var htmlString = '<div class="row">\n\
<h4 style="margin-left:15px;">' + value.pg_name +'</h4>\n';
htmlString += '<div class="col-sm-10"> <div class="btn-group" id="btnmar">\n ';
for(var i=1; i<value.beds+1; i++) {
htmlString += '<button type="button" class="btn btn-primary" style=" width: 71px; ">Bed ' + i + '</button>\n';
}
htmlString += '</div>\n</div>\n';
htmlString += '<div class="col-sm-2">\n\
<div class="panel-group">\n\
<div class="panel panel-primary">\n\
<div class="panel-heading"> Premium Facility</div>\n';
var facArr = value.facility.split(',');
for(var i=0; i<facArr.length; i++) {
htmlString += '<div class="panel-body" style=" padding-top: 5px; padding-bottom: 5px;"><i class="fa fa-television" aria-hidden="true" style="margin-right:15px;"></i>' + facArr[i] +'</div>';
}
htmlString += '</div> </div> </div> </div>';
$('#pgDetails').append(htmlString);
});
}
else {
$( "#toggle" ).hide();
}
}
});
}
</script>
pg_details.php
<?php
//include_once("admin/config.php");
//include("functions.php");
////$pg_name=Getpg($_POST['pg_id']);
//$sharing=$_POST['sharing_id'];//Getting Sharing Value
//
//$sql=mysql_query("SELECT * FROM rooms WHERE room_sharing='$sharing'");
//$count = mysql_num_rows($sql);
//if($count > 0){
// while($row=mysql_fetch_assoc($sql)){
// $data[]= $row;
// }
// $pg_type= array("return"=>1,"count" =>$count,"data" =>$data);
// echo $pg_type = json_encode($pg_type);
//}else{
// $pg_type= array("return"=>0,"count" =>0,"data" =>"");
// echo $pg_type = json_encode($pg_type);
//}
//
$row["pg_id"] = 1;
$row["room_number"] = 102;
$row["pg_name"] = "PG Name 1";
$row["beds"] = 4;
$row["facility"] = "T.V, WiFi, Bed, Washing Machine";
$data[] = $row;
$row["pg_id"] = 1;
$row["room_number"] = 502;
$row["pg_name"] = "PG Name 2";
$row["beds"] = 7;
$row["facility"] = "T.V, WiFi, Bed";
$data[] = $row;
$pg_type= array("return"=>1,"count" =>1,"data" =>$data);
echo $pg_type = json_encode($pg_type);
?>
I wanna make like system that system suggest books to user with JQuery and user like it.
First, at index.php has 2 suggested book. And there is no problem. User can click Like Button. And new book is uploaded insted of liked book. But user can not click the button. The page can not connect functions.js page.
My codes is:
At index.php
<!-- Suggest book -->
<div class="book-box" id="<?php echo $book_id;?>" style="background: #fff;box-shadow: 0 0 1px 1px rgba(0,0,0,.2); min-height: 60px;margin-bottom: 10px!important;bg-444;" data-target="<?php echo $book_id;?>">
<img src="img/<?php echo $ki_image;?>" style="width:100%; height: 150px;padding:0;" alt="">
<div class="container-fluid" style="">
<div class="row" style="">
<div class="caption mt5 p5" style="">
<div class="col-md-12 p0"><strong style="color: #1198BF; cursor: pointer;"><?php echo min_val($book_name,40);?></strong></div>
<div class="col-md-6 mt10" style="font-size: 13px;color: #777;margin-right: 30px;padding: 0;">
<p>2 dostun - 500 nəfər buradadır</p>
</div>
<div class="join " style="margin-top: 10px;float: left;">
<button name="btn_book" class="suggested_join_book" style="font-size: 12px; border-color: #ccc; outline: none; border-radius: 2px; padding: 5px 7px; box-shadow: 0 0 1px 1px rgba(0,0,0,.3); border: none;" data-id="<?php echo $book_id;?>">Abunə ol</button>
</div>
</div>
</div>
</div>
</div>
<div class="clb"></div>
<!-- Finish SuggestBook -->
functions.js is:
$(".suggested_join_book").on("click",function(){
var book_id = $(this).data("id");
$.ajax({
type: "post",
url : "join_book.php",
data: {"book_id":book_id},
success: function(veri){
// $("[data-target="+book_id+"]").addClass('animated fadeOut');
$("[data-target="+book_id+"]").css('display','none');
// $("#"+book_id).load("ajax.php?bol=new_book");
$.ajax({
type: 'post',
url: 'ajax.php?bol=new_book_2',
data: {"userID":'15'},
success: function(arr){
$(".suggest").append(arr);
}
});
}
});
});
ajax.php is:
case "new_book_2":
$userID = $_POST['userID'];
foreach (new_book_2($userID) as $nb) {
$book_name = $nb["ki_name"];
$ki_image = $nb["ki_image"];
$book_id = $nb["ki_id"];
if($ki_image == ""){$ki_image = 'noprofile.jpg';}
?>
<!-- Suggest book -->
<div class="book-box " id="<?php echo $book_id;?>" style="background: #fff;min-height: 83px;margin-bottom: 10px!important;bg-444" data-target="<?php echo $book_id;?>">
<?php
?>
<img src="img/<?php echo $ki_image;?>" style="width:100%; height: 222px;padding:0;border-top-left-radius: 4px;border-top-right-radius: 4px;" alt="">
<div class="container-fluid" style="">
<div class="row" style="">
<div class="caption mt5 p5" style="">
<div class="col-md-12 p0"><strong style="color: #1198BF; cursor: pointer;"><?php echo min_val($book_name,40);?></strong></div>
<div class="col-md-7 mt10" style="font-size: 13px;color: #777;margin-right: 8px;padding: 0;">
<p>2 dostun - 500 nəfər buradadır</p>
</div>
<button name="btn_book sonradan" class="btn btn-primary join_book" data-id="<?php echo $book_id;?>">Abunə ol</button>
</div>
</div>
</div>
</div>
<div class="clb"></div>
<!-- Finish SuggestBook -->
<?php
}
break;
May be you include functions.js before your html tags. Put your click event into the jquery's ready method:
$(document).ready(function(){
$(".suggested_join_book").on("click",function(){
var book_id = $(this).data("id");
$.ajax({
type: "post",
url : "join_book.php",
data: {"book_id":book_id},
success: function(veri){
// $("[data-target="+book_id+"]").addClass('animated fadeOut');
$("[data-target="+book_id+"]").css('display','none');
// $("#"+book_id).load("ajax.php?bol=new_book");
$.ajax({
type: 'post',
url: 'ajax.php?bol=new_book_2',
data: {"userID":'15'},
success: function(arr){
$(".suggest").append(arr);
}
});
}
});
});
});