I am working on a project where I came across where when I click plus sign the data will hide and the appear in the div next to it.
here is the code:
<fieldset class="col-md-4" >
<legend>Services</legend>
<div class="col-md-12" >
<?php
$id = 0;
foreach ($servicesname as $val) {
$id++;
?>
<div class="col-md-12" style="font-size: 16px;" id="itemservices<?php echo $id ?>">
<span style="float:left;" ><?php echo $val[0]['servicename']; ?></span>
<a style="float:right;" href onclick="return addSrvToCart('itemservices<?php echo $id ?>')" >
<strong>₹ <?php echo $val[0]['amount']; ?></strong>
<span class="glyphicon glyphicon-plus-sign" id="id_<?php echo $id; ?>"></span>
</a>
</div>
<?php } ?>
</div>
</fieldset>
and the code for next div:
<fieldset class="col-md-4" >
<legend>Cart</legend>
<div style="list-style:none;" class="no-left-padding" id="cart">
<div class="col-md-12" >
</div>
</div>
<div class="col-sm-12 no-right-padding" style="background-color:#f3f0f0; padding-top:6px; border:1px solid#ccc">
<label class="pull-right">/*what should i write here to show the sum */: ₨ </label>
</div>
<button style="margin-top:10px;" class="btn btn-primary btn-sm pull-right" onclick="bookNowAfterFilter()">Book Now</button>
</fieldset>
And This the Jquery code:
<script>
function addSrvToCart(elem){
alert($('#' + elem).html());
$('#' + elem).hide();
//return false;
//what should i write here the show that hidden div
document.getElementById('summery);
return false;
}
</script>
This is the picture and I want to display the data in the Cart div and show the amount
You need to change in both HTML and Script to achieve the result
Try like this
HTML
<fieldset class="col-md-4" >
<legend>Services</legend>
<div class="col-md-12" >
<?php
$id = 0;
foreach ($servicesname as $val) {
$id++;
?>
<div class="col-md-12" style="font-size: 16px;" id="itemservices<?php echo $id ?>">
<span style="float:left;" ><?php echo $val[0]['servicename']; ?></span>
<a style="float:right;" onclick=" addSrvToCart('itemservices<?php echo $id ?>')" >
₹<strong> <?php echo $val[0]['amount']; ?></strong>
<span class="glyphicon glyphicon-plus-sign" id="id_<?php echo $id; ?>"></span>
</a>
</div>
<?php } ?>
</div>
</fieldset>
and the code for next div:
<fieldset class="col-md-4" >
<legend>Cart</legend>
<div style="list-style:none;" class="no-left-padding">
<div class="col-md-12" id="cart" >
</div>
</div>
<div class="col-sm-12 no-right-padding pull-right" style="background-color:#f3f0f0; padding-top:6px; border:1px solid#ccc">
Total: ₨ <label class="" id="sumAmount">0</label>
</div>
<button style="margin-top:10px;" class="btn btn-primary btn-sm pull-right" onclick="bookNowAfterFilter()">Book Now</button>
</fieldset>
Script:
function addSrvToCart(elem){
var div=$('#' + elem);
div.hide();
$('#cart').append(div.html());
var total = parseInt(div.find('strong').html()) + parseInt($('#sumAmount').html());
$('#sumAmount').html(total);
}
It will produce output as
I think it will help you.
Related
I currently have this code that post for only one user and i want to know if it's possible, that the ajax response can be posted as an update to all logged in users as an update on the website. I appreciate all efforts.
<form method="post" action="" id="postForm">
<input type="hidden" name="userId" id="userId" value="<?php echo $_SESSION['USERID']; ?>" />
<select name="type" class="form-control" style="border:1px solid #eee; border-radius:5px; width:auto !important;">
<option value="">select type of post</option>
<option value="default">Normal Post</option>
<option value="Testimonies">Testimonies</option>
<option value="Prayer">Prayer Request</option>
<option value="counselling">Counselling</option>
<option value="Dreams">Dreams Interpretation</option>
</select>
<textarea class="form-control" style="border:none; resize:none;" rows="1" name="post" id="post" placeholder="What's God saying through you today? <?php $text = explode(' ', $_SESSION['NAME']); echo $text[0]; ?>"></textarea>
<button type="submit" value="postForm" class="submitIt btn btn-info btn-flat">Post</button>
</form>
The AJAX Part
<script>
$(document).ready(function(){
$( "body" ).delegate( ".submitIt", "click", function(e) {
e.preventDefault();
e.stopPropagation();
//the button value
$url = "http://localhost/christ/ajaxPages/";
var buttonValue = $(this).val();
//alert(buttonValue);
if(buttonValue == "postForm") {
var formdata = $('#postForm').serialize();
//alert(formdata);
$.ajax({
type: "POST",
url: $url + "addit.php",
data: formdata,
success: function(data){
$("#discuss").append(data);
$("#post").each(function(){autosize.destroy(this);});
$("#post").val("");
}
})
});
</script>
This is the addit.php file called by above ajax
<?php
include '.././config.php';
//waste in dispose
$arr[] =0;
$db_con = connect();
$sect = $_POST['post'];
$type = $_POST['type'];
$userId = $_POST['userId'];
$date = date('Y-m-d H:i:s');
//time of psoidting
$time = strtotime($date);
$sql = "insert into post(post_body,userId,post_type,date) values(:data,:userId,:type,:dateposted)";
$bio = $db_con->prepare($sql);
$bio->bindParam('data', $sect);
$bio->bindParam('type', $type);
$bio->bindParam('userId', $userId);
$bio->bindParam('dateposted', $date);
$bio->execute();
$arr = $bio->errorInfo();
if($arr[2] == "") {
$disc = $db_con->prepare("select * from post where post_body = :text and userId = :userId");
$disc->bindParam("text", $sect);
$disc->bindParam('userId', $userId);
$disc->execute();
$row = $disc->fetch();
$_SESSION['postId'] = $row['post_id'];
//let us retrive
echo '<!-- Box Comment -->
<div class="box box-widget" id="lofty-'.$row['post_id'].'">
<div class="box-header with-border" style="border-radius:5px 5px 0 0;">
<div class="user-block">
<img class="img-circle" src="'.$url.'/'.userName('icon', $_SESSION['USERID']).'" alt="User Image">
<span class="username"><a style="color:#1da1f2;" href="#">'.ucfirst($_SESSION['NAME']).'</a></span>
<span class="description">Shared - ';
echo humanTiming($time);
echo '</span>
</div>
<!-- /.user-block -->
<div class="box-tools">';
if($row['userId'] == $_SESSION['USERID']) {
echo '<div class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span style="color:#fff">Dropdown Example</span>
<span class="caret"></span></a>
<ul class="dropdown-menu shadow">
<li><a href="#"><button type="button" data-toggle="modal" data-target="#editModal" class="btn btn-box-tool edit" id="edit-post-'.$row['post_id'].'"><i class="fa fa-edit"></i> Edit</button></li>
<li><button type="button" class="btn btn-box-tool submitIt" value="delete" name="del-'.$row['post_id'].'-'.$_SESSION['USERID'].'-post"><i class="fa fa-trash-o"></i> Delete</button></li>
</ul>
</div>';
}
echo '</div>
<!-- /.box-tools -->
</div>
<!-- /.box-header -->
<div class="box-body">
<p style="white-space:pre-wrap";><span id="replace-'.$row['post_id'].'">'.$sect.'</span></p>
<div style="margin-left:-10px; margin-right:-10px; padding:4px 4px 0 4px;">
<div class="col-lg-6" style="text-align:left">
<span class="text-muted">
<button style="background:none; border:none;" class="btn btn-box-tool BigLike" name="like-'.$row['post_id'].'-'.$_SESSION['USERID'].'">
<i class="fa fa-thumbs-o-up"></i> <span id="change'.$row['post_id'].'"></span></button>
<span id="seeIt'.$row['post_id'].'"></span><span id="seeItbefore'.$row['post_id'].'"></span></span>
</div>
<div class="col-lg-6" style="text-align:right">
<span class="text-muted">
<span id="seeIt2'.$row['post_id'].'"></span><span id="seeItbefore2'.$row['post_id'].'"></span>
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer box-comments" style="background:none; margin:0;" id="comment'.$row['post_id'].'"></div>
<!-- /.box-footer -->
<div class="box-footer" style="border:none; padding-top:1px;">
<form action="." method="post">
<img class="img-responsive img-circle img-sm" src="'.$url.'/'.userName('icon', $_SESSION['USERID']).'" alt="user image">
<!-- .img-push is used to add margin to elements next to floating images -->
<div class="img-push">
<textarea type="text" style="border-radius:20px; background:#eee; border:none; resize:none; overflow:hidden" rows="1" class="form-control input-sm comment-'.$_SESSION['USERID'].'" name="comment-'.'3-'.$row['post_id'].'-'.$_SESSION['USERID'].'" placeholder="Press enter to post comment"></textarea>
</div>
</form>
</div>
<!-- /.box-footer -->
</div>
<!-- /.box-widget -->
<!-- /.box -->';
} else {
echo 'Failed';
}
?>
I want to know if it's possible to modify this code to post the ajax response to all logged in users on the website rather than just the user that made the post. Forgive my English
here my problem is the values that are selected through append are not getting inserted in to the post value..here am pasting my code
<div id="update_new_<?php echo $value->id;?>" class="update_new_<?php echo $value->id;?>">
<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 update_more_<?php echo $value->id;?>"><i
class="fa fa-plus"></i> Add More
</a></strong>
</div>
</div>
</div>
here is my script please have a look
<script type="text/javascript">
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>');
maxAppends++;
$(".update_new_"+id).append(update_new);
}
</script>
Here while clicking to add more fields its coming correctly but the values selected in that field is not getting while passing the value through post and i have a doubt that if it is caused by using dynamic way off adding the data.
The problem i figured out is the problem is the <div id="update_new_<?php echo $value->id;?>"> is inside a foreach loop so how can we done this with in a foreach loop.
In your script, change .update_new_ to #update_new_
this picture is pagination and inspect values on edit button : enter image description here
my problem is that unable to edit value on next page in ajax, on first page edit button working,
and successfully edit validation not working after edit value.
on edit button values coming in json format i have only some knowledge of json and ajax
My database table:
-----------------------------------
sport_id | sport_name
-------------------------------------
1 | Volleyball
2 | Basketball
----------------------------------
table name is:- sports
my code is like that
controller
===========
public function add_sport() {
unset($_POST['gym_account_id']);
if(isset($_POST['sport_id'])){
unset($_POST['sport_id']);
$response = $this->queryData->sportAddData($_POST);
}else{
$sport_id = $_POST['sport_id'];
// alert($sport_id);
$sport_name = array("sport_name" => $_POST['sport_name']);
$response = $this->queryData->sportEditData($sport_name,$sport_id);
}
$this->Sports();
}
model
========
public function sportAddData($data) {
$this->db->insert('sports', $data);
$insert_id = $this->db->insert_id();
return $insert_id;
}
public function sportEditData($sport_name,$sport_id) {
$this->db->where('sport_id', $sport_id);
$this->db->update('sports', $sport_name);
}
view
======
<div class="page-title">
<div class="title_left">
<div class="alert alert-success alert-dismissible fade in" role="alert" style="display: <?php echo (!empty($_GET['success'])) ? 'block' : 'none'; ?>">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span>
</button>
<strong>Success!</strong> <?php echo $_GET['success']; ?>
</div>
</div>
<div class="title_right">
<div class="col-md-12 col-sm-5 col-xs-12 form-group pull-right top_search" style="text-align: right; margin-bottom: 26px; margin-right: -4px;">
<button type="button" class="btn btn-dark create_sport1">Create</button>
<button type="button" class="btn btn-dark delete_items" >Delete</button>
<button type="button" class="btn btn-dark call_delete" data-toggle="modal" data-target=".bs-example-modal-sm" style="display: none;" >Delete Athlete</button>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="row sport_form_block" id="add_sports" style="display: none;">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2 class="form_title1">Create New Sport</h2>
<div class="clearfix"></div>
</div>
<div class="x_content">
<br />
<form id="demo-form2" method="POST" data-parsley-validate class="form-horizontal form-label-left sport_form">
<?php
$userType = $this->session->userData('userType');
$gymAccountId = $this->session->userData('gym_account_id');
if($userType == 1){
?>
<?php }else{ ?>
<input type="hidden" name="gym_account_id" id="gym_account_id" value="<?php echo $gymAccountId; ?>" />
<?php } ?>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="sport_name">Sport Name <span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" id="sport_name" name="sport_name" required="required" class="form-control col-md-7 col-xs-12 edit_sportname">
</div>
</div>
<div class="ln_solid"></div>
<div class="form-group">
<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
<input type="hidden" name="sport_id" value="" class="editsportid" id="editsportid" />
<button class="btn btn-primary close_form" data-div="sport_form_block" type="button">Cancel</button>
<button class="btn btn-primary reset_sport_form" type="reset">Reset</button>
<!-- <button type="button" class="btn btn-success submit_athlete1" data-url="<php echo base_url(); ?>athlete/add_athlete" data-table="<php echo base_url(); ?>athlete/get_athlete" data-form="athlete_form" data-div="athlete_form_block">Submit</button>-->
<button type="submit" class="btn btn-success submit_athlete1" data-url="<?php echo base_url(); ?>Index/add_sport" data-table="<?php echo base_url(); ?>sport/get_athlete" data-form="sport_form" data-div="sport_form_block">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>Sport(s)<small></small></h2>
<div class="clearfix"></div>
</div>
<div class="x_content">
<table id="sport-athlete-datatable-responsive" class="table table-striped table-bordered dt-responsive nowrap bulk_action" cellspacing="0" width="100%">
<thead>
<tr>
<th class="no-sort" style="width: 30px;" ><input type="checkbox" id="check-all" class="flat check_all" data-check="athlete_list"></th>
<th>Id</th>
<th>Sport</th>
<th class="no-sort" style="width: 50px;" >Edit</th>
</tr>
</thead>
<tbody>
<?php foreach ($data['athletes'] as $key => $value) { ?>
<tr>
<!-- <td><input type="checkbox" id="<php echo $value['athlete_id']; ?>" class="flat athlete_list multiple_delete"></td>-->
<td><input type="checkbox" id="<?php echo $value['sport_id']; ?>" class="flat athlete_list multiple_delete"></td>
<td><?php echo $value['sport_id']; ?></td>
<td><?php echo $value['sport_name']; ?></td>
<!--<td></i></td>-->
<td><button class="edit_sport option_icon" data-json='<?php echo $value['sport_id'] . ',' . $value['sport_name'] ?>' data-block="sport_form_block" data-form="sport_form" ><i class="fa fa-edit"></i></button></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
js
==
$('.edit_sport').on('click', function (e) {
//$('.edit_sport').on('click', function (e) {
$('#add_sports').slideDown();
id = $(this).attr("data-json");
var arr = id.split(',');
$('.edit_sportname').val(arr[1]);
$('.editsportid').val(arr[0]);
alert(arr);
console.log(arr);
$('#function').val("update");
$('.form_title1').html('Edit Sports');
$('.' + $(this).data("block")).show();
$("html, body").animate({scrollTop: 0}, "slow");
});
Because you use onclick to bind event on button which will not apply for new element add to DOM via ajax call. You can use delegate or on to attach an events.
i want to include a else statement after the completion of the block after the second if for category equal to helathcare ....now i want another else for finance but i am not getting where excatly to place that else
i have a confusion on where to keep the else for finance and 2 more categories
now whenever i try to place the one else at the last goes unrecable to its if statement i donno its very confusing as to where to place 2 more else if statments for 2 more categories
<?php
global $row2;
if(isset($_POST['category']))
{
if($_POST['category']== 'Healthcare')
{
$query = "select *from event where category = 'Healthcare';";
$result=mysqli_query($conn,$query)or die(mysqli_error($conn));
while($row2= mysqli_fetch_array($result))
{
?>
<div class="events events-full event-list">
<div class="container">
<div class="row">
<div class="col-md-9 col-sm-8">
<!--Blog Post Start-->
<div class="blog-post">
<div class="post-thumb">
<div class="link-wrap"> <i class="fa fa-search"></i> <i class="fa fa-link"></i> </div>
<img src="images/gallery/<?php echo $row2['event_image']?>" alt='user'></div>
<div class="event-text">
<div class="event-counter"></div>
<h4> <?php echo($row2['title']); ?> </h4>
<p><?php echo($row2['descrption']); ?></p>
<p><span class="glyphicon glyphicon-map-marker"><?php echo($row2['location']); ?></span></p>
<p><span class="glyphicon glyphicon-grain"><?php echo($row2['organizer']); ?></span></p>
<a class="nd" href="">
<form action="eventdetail.php" method="post">
<input type='hidden' value="<?php echo $row2['id']; ?>" name='id'/>
<button type="submit" class="btn btn-primary" name="detail" value=”detail”>Event Detail</button>
</div>
</a> </div>
</div>
</form>
<!--Blog Post End-->
<?php }
}
}
else
{
global $row2;
$query = "select *from event;" ;
$result=mysqli_query($conn,$query)or die(mysqli_error($conn));
while($row2= mysqli_fetch_array($result))
{
?>
<div class="events events-full event-list">
<div class="container">
<div class="row">
<div class="col-md-9 col-sm-8">
<!--Blog Post Start-->
<div class="blog-post">
<div class="post-thumb">
<div class="link-wrap"> <i class="fa fa-search"></i> <i class="fa fa-link"></i> </div>
<img src="images/gallery/<?php echo $row2['event_image']?>" alt='user'></div>
<div class="event-text">
<div class="event-counter"></div>
<h4> <?php echo($row2['title']); ?> </h4>
<p><?php echo($row2['descrption']); ?></p>
<p><span class="glyphicon glyphicon-map-marker"><?php echo($row2['location']); ?></span></p>
<p><span class="glyphicon glyphicon-grain"><?php echo($row2['organizer']); ?></span></p>
<a class="nd" href="">
<form action="eventdetail.php" method="post">
<input type='hidden' value="<?php echo $row2['id']; ?>" name='id'/>
<button type="submit" class="btn btn-primary" name="detail" value=”detail”>Event Detail</button>
</div>
</a> </div>
</div>
</form>
<!--Blog Post End-->
<?php } } ?>
?>
You can't put multiple else blocks along with the if block. However, you can use multiple(as many as you want) elseif/else if blocks along with the if block, like this:
if($_POST['category'] == 'Healthcare'){
...
}elseif($_POST['category'] == 'Finance'){
...
}elseif($_POST['category'] == '...'){
...
}else{
...
}
Here's the reference: http://php.net/manual/en/control-structures.elseif.php
Part of your problem seems to be poor formatting. If you lined up your open and close tags for your if statements I think you would be able to see this better. Having said that, you can add any elseif/if clauses for the category if where I marked below:
<!--Blog Post End-->
<?php
} // closes while loop
} else{ } // closes healthcare if, add extra else here
} // closes POST if
else
{
I am using bootstrap 3 and I am making a social networking site, this code here is a part of a panel which shows the posts.The problem is it is showing the comments on toggle but the comments are not appearing within the footer it is crossing it...So what is wrong in my or how can I extend the panel footer?
Here's the code:
<div class="panel-footer">
Like <span class="glyphicon glyphicon-thumbs-up"></span>
Comments
<div id='toggleComment<?php echo $idp;?>' style="display:none;">
<form action="" method="POST"><!--FORM COMMENT-->
<div class="form-group">
<div class="rows" >
<div class="col-sm-1" style="padding-right:2px;">
<div class="compic">
<img src="<?php echo $profilepic; ?>" style="width:100%;height:100%;" />
</div>
</div>
<div class="col-sm-11" style="padding-left:3px; padding-bottom:7px">
<textarea class="form-control expandable pull-left" name="comment<?php echo $idp;?>" id="comment" placeholder="Write a comment..." required>
</textarea>
</div>
</div>
<hr>
<button type="submit" class="btn btn-primary pull-right" name="subcom<?php echo $idp;?>"><b>Comment</b></button>
<div class="clearfix"></div>
</div></form>
<div class="rows" >
<?php
$postid=$idp;
$postby=$id;
$postto=$uid;
if(isset($_POST['subcom'.$postid]))
{ $postbody=$_POST['comment'.$postid];
if($postbody!="")
{$res=mysqli_query($con,"INSERT INTO comment VALUES('','$postby','$postto','$postbody','$postid')");}
}
$show=mysqli_query($con,"SELECT * FROM comment WHERE postid='$idp' ORDER by id");
while($show_row=mysqli_fetch_array($show))
{
$commentbyid=$show_row['cby'];
$combody=$show_row['cbody'];
$cbyquery=mysqli_query($con,"SELECT * FROM user WHERE id='$commentbyid'") or die(mysqli_error($con));
$cby=mysqli_fetch_array($cbyquery);
$cpic=$cby['profpic'];
if ($cpic== "" || !file_exists("userdata/profile_pics/$cpic"))
{
$cpic = "images/default_pic.jpg";
}
else
{
$cpic = "userdata/profile_pics/".$cpic;
}
$cname=ucfirst(strtolower($cby[1]));
$csname=ucfirst(strtolower($cby[2]));
?>
<div class="col-sm-1" style="padding-right:2px;">
<div class="compic">
<img src="<?php echo $cpic; ?>" style="width:100%;height:100%;" />
</div>
</div>
<div class="col-sm-11" style="padding-left:3px;">
<?php echo $cname." ".$csname;?><br>
<?php echo $combody;?>
</div>
<?php
}
?></div>
</div><!--Toggle Ends here-->
</div>
finally got it it was because of the <div class="clearfix"></div> and it got solved when I used it just after </div><!--Toggle Ends here-->