No text change of anchor on toggle please provide me some suggestion
Html:
+Flight Details
<div id="flight_<?php echo $flightlist->id; ?>" class="minDetailBox addmarginB10 borT">
<div class="col1">
<div class="padding">
<div class="airLogo"> <span class="airSprites LS2"> </span>
<p>JET Lite</p>
</div>
</div>
</div>
</div>
Script:
function showHide(id) {
var minDetails = document.getElementById(id);
$(minDetails).toggle('slow');
($(this).text() === "+Flight Details") ? $(this).text("-Flight Details") : $(this).text("+Flight Details");
return false;
}
Pass your element as well like onClick="return showHide('flight1',this)"
function showHide(id,element) {
var minDetails = document.getElementById(id);
$(minDetails).toggle('slow');
($(element).text() === "+Flight Details") ?
$(element).text("-Flight Details") :
$(element).text("+Flight Details");
return false;
}
You can try something like this
+Flight Details
function showHide(id, link) {
$('#' + id).toggle('slow');
($(link).text() === "+Flight Details") ? $(link).text("-Flight Details") : $(link).text("+Flight Details");
return false;
}
+Flight Details
jQuery('a.toggle')
.click(function(e) {
var id = jQuery(this).attr('id');
jQuery('#'+id).toggle('slow');
if(jQuery('#'+id).css('display') == 'none') {
jQuery(this).html("+Flight Details");
} else {
jQuery(this).html("-Flight Details");
}
e.preventDefault();
});
You can do this as below,
jQuery Code
$(function()
{
$('div[id^="flight_"]').hide();
$(document).on('click','.fnt-size12',function(e)
{
e.preventDefault();
var $that = $(this);
$(this).next('#flight1').toggle();
if($that.html() == '+Flight Details') {
$that.html('-Flight Details');
} else {
$that.html('+Flight Details');
}
})
});
Your HTML
+Flight Details
<div id="flight1" class="minDetailBox addmarginB10 borT">
<div class="col1">
<div class="padding">
<div class="airLogo"> <span class="airSprites LS2"> </span>
<p>JET Lite</p>
</div>
</div>
</div>
</div>
See i have modified your HTML code and added new few lines of jQuery code.
Related
I have below code to get more results on page scroll.
It works fine on localhost and on server laptop/desktop.
It does not work on mobile and does not load more results on scroll.
I cannot figure it out why this is happening or what is causing this not to work on mobile.
<?php
$getItemLID = $dba->prepare('SELECT MAX(id) as id FROM items
where status = ? AND ename like ?');
$getItemLID->bind_param('ss', $status,$param);
$getItemLID->execute();
$resultLID = $getItemLID->get_result();
$rowLID = $resultLID->fetch_assoc();
$thelastid = $rowLID['id'];
$status = 1;
$getscategory = $dba->prepare('SELECT * FROM mytable
where status = ?
order by id asc');
$getscategory->bind_param('s', $status);
$getscategory->execute();
$resultGSC = $getscategory->get_result();
while ($rowGSC = $resultGSC->fetch_assoc()) {
$scid = $rowGSC['id'];
$scename = $rowGSC['ename'];
?>
<div class="message_box" data-id="<?php echo $scid; ?>" style="padding-right: 5px;">
<div class="portfolio-item-wrap" style="border-radius: 3%;">
<span class="portfolio-description">
<h3><?php echo $scename; ?></h3>
</span>
</div>
</div>
<?php } ?>
<div id="msg_loaderw" style="display: none;">
<div class="card">
<div class="card-body">
<div class="d-flex align-items-center">
<strong>Loading...</strong>
<div class="spinner-border ml-auto" role="status" aria-hidden="true">
</div>
</div>
</div>
</div>
</div>
<div id="msg_loader">
</div>
<script>
$(document).ready(function () {
$(window).scroll(function () {
var thislastid = "<?php echo $thelastid; ?>";
if($(window).scrollTop() == ($(document).height() - $(window).height())) {
$("#msg_loaderw").show();
var msg_id = $(".message_box:last").data("id");
$.ajax({
type: "POST",
url: "inc/items/search_items_get.php",
data: {msg_id: msg_id},
cache: false,
success: function (data) {
//Insert data after the message_box
$(".message_boxx").append(data);
if (msg_id == thislastid) {
$("#msg_loaderw").hide();
$("#msg_loader").html('<hr><div class="card"><div class="card-body"><div class="align-items-center"><strong><center>That is all what we have for now.</center></strong></div></div></div>');
}
}
});
}
});
});
</script>
Below is : inc/items/search_items_get.php
<?php
include ('../default/db.php');
if (isset($_POST['msg_id']) && isset($_POST['msg_id']) !== NULL) {
$msg_id = $_POST['msg_id'];
$status = 1;
$limit = 12;
$getItem = $dba->prepare('SELECT * FROM mytable
where id > ? AND status = ?
order by id asc');
$getItem->bind_param('ss', $msg_id,$status);
$getItem->execute();
$resultItem = $getItem->get_result();
while ($rowItem = $resultItem->fetch_assoc()) {
$itemID = $rowItem['id'];
$itemName = $rowItem['ename'];
?>
<div class="message_box" data-id="<?php echo $itemID; ?>" style="padding-right: 5px;">
<div class="portfolio-item-wrap" style="border-radius: 3%;">
<span class="portfolio-description">
<h5><?php echo $itemName; ?></h5>
</span>
</div>
</div>
<?php
}
} else {
echo "Message ID is empty";
}
?>*emphasized text*
It seems it's a script issue just try changing the code a bit , hopefully it will work:
<script>
$(document).ready(function () {
$(window).scroll(function () {
var scrollHeight = $(document).height();
var scrollPosition = $(window).height() + $(window).scrollTop();
if ((scrollHeight - scrollPosition) / scrollHeight === 0) {
$("#msg_loaderw").show();
var msg_id = $(".message_box:last").data("id");
$.ajax({
type: "POST",
url: "inc/items/search_items_get.php",
data: {msg_id: msg_id},
cache: false,
success: function (data) {
//Insert data after the message_box
$(".message_boxx").append(data);
if (msg_id == thislastid) {
$("#msg_loaderw").hide();
$("#msg_loader").html('<hr><div class="card"><div class="card-body"><div class="align-items-center"><strong><center>That is all what we have for now.</center></strong></div></div></div>');
}
}
});
}
});
});
</script>
I'm relatively new to the world of programming and this is my first question on stack overflow. I have to create a system written in php and jquery that allows to order a series of images and, based on the order, create a banner-style animation. The only problem is that when the script selects the images from the div to create the animation they disappear. thanks in advance for your collaboration
the javascript
$(document).ready(function () {
const images = document.querySelectorAll('.imgw');
$('#preview').html(images[0]);
$("#genera").click(function () {
setInterval(banner, 2500);
var index = 1;
});
});
const banner = () => $('#preview').fadeOut('slow', function () {
$(this).html(images[index]);
$(this).fadeIn('slow', function () {
if (index == images.length - 1) {
index = 0;
} else {
index++;
}
});
})
the html file
<section>
<div class="row" style="margin-top:25px;">
<div class="col text-center">
<h2 style="margin-top:25px;">Anteprima</h2>
<div id="preview">
</div>
</div>
</div>
</section>
<section>
<div class="row" id="slides" style="margin-top:25px;">
<div class="col text-center">
<!-- <div id="box"> -->
<h2 style="margin-top:25px;">Slides</h2>
<ul id="sortable">
<?php
$html = "";
$count = 1;
foreach ($images as $img) {
$url = $img["url"];
$size = $img["size"];
$humanSize = $img["human_size"];
$html .= "\t\t<img src='{$url}' class='imgw' id='{$count}' alt='image_{$count}' />\n";
$count++;
}
echo $html;
?>
</ul>
</div>
I read the documentation better and solved the problem
the javascript
var images = $('.ui-sortable').children("img").clone();
var index = 1;
const banner = () => $('#anteprima').fadeOut('slow', function () {
$(this).html(images[index]);
$(this).fadeIn('slow', function () {
if (index == images.length - 1) {
index = 0;
} else {
index++;
}
});
})
setInterval(banner, 2500);
i've been trying to learn yii recently and so i started to work on an simple form with bootstrap. im using yii 1.1.x version not version 2 so i had to install bootstrap manually and write coding based on it.
anyway coming back to the problem it seems that my has-success class is being called correctly by jquery but it does'nt seem so for the has-error...
can someone help and im grateful for your help
<script>
$(document).ready(function() {
$('#contact_name').on('input', function() {
var input = $(this);
var is_name = input.val();
if (is_name) {
$('#contact_name').removeClass("has-success").addClass('has-error');
} else {
$('#contact_name').removeClass("has-error").addClass('has-success');
}
});
});
</script>
<h1>Example Form Validation</h1>
<br>
<div class="form " id="cla">
<?php $form=$this->beginWidget('CActiveForm',array( 'id' =>'form','htmlOptions'=> array('class'=> 'form-horizontal', 'name' => 'forvalidate', 'id' => 'registration-form' ))); ?>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<div class="form-group col-lg-5" id='contact_name'>
<?php echo $form->label($model,'name',$htmloptions = array('class'=>'control-label ',)); ?>
<div class="controls">
<?php echo $form->textField($model,'name',array('name' =>'name' ,'class'=>'form-control col-xs-5', 'aria-describedby'=>'inputSuccess4Status')); ?>
</div>
</div>
</div>
<?php $this->endWidget(); ?>
</div>
<!-- form -->
Try
$('#contact_name').on('input', function() {
var input = $(this);
var is_name = input.val();
if (!is_name) {
$('#contact_name').parent().removeClass("has-success").addClass('has-error');
} else {
$('#contact_name').parent().removeClass("has-error").addClass('has-success');
}
});
I think "has-error" and "has-success" classes don't apply directly on the input but the div where the inputs are
You have to add these classes. See the highlighted code below:
$(document).ready(function() {
$('#contact_name').on('input', function() {
var is_name = $(this).val();
if (is_name) {
$('#contact_name').removeClass("has-success").addClass('has-error');
// ^^^^^^^^^^^^^^^^^^^^^^^
} else {
$('#contact_name').removeClass("has-error").addClass('has-success');
// ^^^^^^^^^^^^^^^^^^^^^^^^
}
});
});
I need to get the id of the productbox div in this jquery code.i tried $this.attr('id) but the result is object object or undefined.how can i get the id of productbox div? thanks in advance
Javascript:
$('body').on('mouseenter', 'div.productbox', function()
{
buttonDiv = $(this).children('div.roll');
myTimeout = setTimeout(function()
{
Divid = ?;
buttonDiv.toggle();
}, 500);
});
$('body').on('mouseleave', 'div.productbox', function()
{
buttonDiv.hide();
clearTimeout(myTimeout);
});
$('body').on('hover', 'div.productbox', function()
{
var buttonDiv = $(this).children('div.roll1');
buttonDiv.toggle();
});
HTML:
<div id="40" class="productbox">
<span class="new">Yeni</span>
<div class="roll" style="display: none;">
<input type="button" value="139"> Like <input type="button" value="34"> Comment
</div>
<div class="productpicture" onclick="rload(40)">
<img style="margin:auto; width:180px;overflow:hidden;display:block" src="pictures/40.jpg">
</div>
<div class="ps">
<div class="productname">Giysi</div>
<div class="companyname" onclick="go('2');">Koton</div>
<div class="price">9.99 TL</div>
</div>
</div>
You can take advantage of closure like this:
<script type="text/javascript">
$('body').on('mouseenter', 'div.productbox', function()
{
var $productBox = $( this );
buttonDiv = $productBox.children('div.roll');
myTimeout = setTimeout(function ()
{
Divid = $productBox.attr('id');
buttonDiv.toggle();
}, 500);
});
$('body').on('mouseleave', 'div.productbox', function ()
{
buttonDiv.hide();
clearTimeout(myTimeout);
});
$('body').on('hover', 'div.productbox', function ()
{
var buttonDiv = $(this).children('div.roll1');
buttonDiv.toggle();
});
</script>
<div id="40" class="productbox">
<span class="new">Yeni</span>
<div class="roll" style="display: none;">
<input type="button" value="139">
Like
<input type="button" value="34">
Comment
</div>
<div class="productpicture" onclick="rload(40)">
<img style="margin:auto; width:180px;overflow:hidden;display:block" src="pictures/40.jpg">
</div>
<div class="ps">
<div class="productname">Giysi</div>
<div class="companyname" onclick="go('2');">Koton</div>
<div class="price">9.99 TL</div>
</div>
</div>
The reason you are getting 'undefined' etc is because you are actually requesting the window for its ID.
What you need to do is declare a local variable for the div and then inside your timeout use that variable to get the ID.
$('body').on('mouseenter', 'div.productbox', function() {
var $this = $(this);
var buttonDiv= $this.children('div.roll');
var myTimeout = setTimeout(function() {
var Divid= $this.attr('id');
buttonDiv.toggle();
}, 500);
});
you need to do this:
$('body').on('mouseenter', 'div.productbox', function() {
myTimeout = setTimeout((function(self) {
return function() {
buttonDiv = $(self).children('div.roll');
Divid= $(self).attr("id");
console.log(Divid);
buttonDiv.toggle();
}
})(this), 500);
});
check the JSFiddle for complete working code: http://jsfiddle.net/kBRyu/2/
I am trying to hide or show the div based on the div id from the php function. I am not able to make it work, please help me.
Javascript:
<script>
showOrHide(id) {
var elem=getElementById(id);
if(elem.style.visibility="hidden")
elem.style.visibility="visible";
else
elem.style.visibility="hidden";
}
</script>
PHP Script:
<?php
function display_link($link_id,$upvote_array,$downvote_array,$divid) {
?>
More links
<div id="<?php echo $divid ?>" style="visibility:hidden;">
</div>
<?php } ?>
Here's a cleaned-up version of your function.
function showOrHide(id) {
var elem = document.getElementById(id);
elem.style.visibility = (elem.style.visibility === 'hidden')? 'visible' : 'hidden';
}
<script>
function showOrHide(id){
var elem = getElementById(id);
if(elem.style.visibility=="hidden"){
elem.style.visibility="visible";
} else {
elem.style.visibility="hidden";
}
}
</script>
<?php
function display_link($link_id,$upvote_array,$downvote_array,$divid)
{
?>
More links
<div id="<?php echo $divid ?>" style="visibility:hidden;">
</div>
1 - visibility == 'hidden'
2 - missing ; after visibility="visible" and ="hidden"
3 - href="javascript:showOrHide('')" - missing '' inside your javascript function
Try this
<script>
function showOrHide(id){
var elem = document.getElementById(id);
elem.style.visibility = (elem.style.visibility === 'hidden')? 'visible' : 'hidden';
}
</script>
<?php
function display_link($link_id,$upvote_array,$downvote_array,$divid)
{
?>
More links
<div id="<?php echo $divid ?>" style="display:hidden;">
</div>
<?php
}
?>