having trouble with jquery .context and .index - php

here is my PHP code to generate a dynamic product table:
while($item = mysqli_fetch_array($result))
{
enter code here
$i++;
$pic = "cartimg/".$item[2];
echo "<div class='prod_box'".$i.">
<div class='center_prod_box'>
<div class='product_title'><a>".$item[1]."</a></div>
<div class='product_img'><a ><img src='".$pic."' alt='' border='0' /></a></div>
<div class='prod_price'><span class='reduce'>".$item[3]."$</span> <a class='price'>".$item[4]."$</a></div>
</div>
<div class='prod_details_tab'> <a class='prod_buy'>Add to Cart</a> <a class='prod_details'>Details</a> </div>
</div>";
}
?>
and here is my jQuery to respond to the clicked event to add the product into the shopping cart
enter code here
cart.addBuyButton(".prod_buy",{
name:'MacBook', // Item name appear on the cart
thumbnail:'media/macbook.jpg', // Thumbnail path of the item (Optional)
price:$("span").index(0), // Cost of the item
shipping:20
// Shipping cost for the item (Optional)
});
prettyPrint();
and here is the query for addBuyButton function
enter code here
self.addBuyButton=function(target,data){$(target).click(function(){self.cart.add(data)
the problem is that, I will have 10 containers, contain 10 products, with the same class name and Id names, and I cant figure out how to read the amount of ".$item[4]."$ if the customer clicked on Add to Cart of different products.
right now the function inserts 12 as the price.
please help me out here, I have surf through many jQuery tutorials but wasn't lucky to find a way.
thanks

Instead of having an addBuyButton for each item on the jQuery I would have just one event listener that handles all of it like this (I personally don't like huge chunks of php in quotes because my IDE doesn't color highlight so pardon my php syntax. You don't have to follow it if you don't like it):
PHP
<div id="products">
<?php while ($item = mysqli_fetch_array($result)) : ?>
<!-- additional code here -->
<div class="product prod_box<?php echo ++i; ?>">
<div class="center_prod_box">
<div class="product_title"><?php echo $item[1] ?></div>
<div class="product_img"><img src="cartimg/<?php echo $item[2] ?>" border="0" /></div>
<div class="prod_price">
<span class="reduce"><?php echo $item[3] ?>$</span>
<a class="price"><?php echo $item[4] ?>$</a>
</div>
</div>
<div class="prod_details_tab">
<a class="prod_buy">Add to Cart</a>
<a class="prod_details">Details</a>
</div>
</div>
<?php endwhile; ?>
</div>
JAVASCRIPT
$('#products').on('click', '.prod_buy', function() {
var product = $(this).closest('.product');
cart.add({
name: product.find('.product_title').first().text(),
thumbnail: product.find('.product_img').first().text(),
price: product.find('.price').first().text(),
shipping: 20
});
});
So that's one event listener for ALL of your prod_buy buttons and it gets the values for the product out of the DOM and adds it to the cart.
If you need any further help add a comment to this post and I'll add more to my answer.

Related

<pre> tag messing with UI

I returning my data to build a list group. All is fine but when the data contains <pre> tag it messes my display.
My list group as follows.
if (isset($BS_array)){
//Create a list group to show results
echo '<div class="list-group">';
foreach($BS_array as $result){
?>
<!-- Build list group -->
<div class="list-group-item list-group-item-action" aria-current="true">
<div class="d-flex w-100 justify-content-between">
<!-- Incident number goes here -->
<h5 style="cursor: pointer;" id="<?php echo $result['number']; ?>" onclick="getINCDetails(this.id)" class="mb-1"><?php echo $result['number']; ?></h5>
</div>
<!-- Description goes here -->
<p class="mb-1"><?php echo $result['description']; ?></p>
<small>
<?php
//List BS in INC card
echo $result['state'];
?>
</small>
</div>
<?php
}
echo '</div>';
}
?>
The way when all goes ok should be like this.
But at times, $result['description'], contains the word <pre>, which messes things up.
It will look like this.
How do I fix/circumvent this problem?
If you dont require html tags to actually work on the description just use htmlentities():
<?php echo htmlentities($result['description']); ?>
That will actually show instead of the browser considering it html tag.

Require a solution for full screen image slide show using cakephp and foundation framework

code below is long but really straight forward only require code to put forward ability to slide from first slide to last slide to that return to first slide to traverse.
<div class="orbit" role="region" aria-label="Favorite Space Pictures" data-orbit>
<div class="orbit-wrapper">
<div class="orbit-controls">
<button class="orbit-previous"><span class="show-for-sr">Previous Slide</span>◀︎</button>
<button class="orbit-next"><span class="show-for-sr">Next Slide</span>▶︎</button>
</div>
<ul class="orbit-container">
<?php
foreach($employers as $employer){
echo '<li class="orbit-slide">
<figure class="orbit-figure">
'.$this->Html->image($employer['image'], ['alt'=>'employer image',
"class"=>"orbit-image"]).'
<figcaption class="orbit-caption">'.
$employer['brief'].
$employer['name'].
$employer['desg'].
$employer['created'].'
</figcaption>
</figure>
</li>
';
}
?>
</ul>
</div>
<nav class="orbit-bullets">
<?php
$i=0;
foreach($employers as $employer){
echo '<button data-slide="'.$i.'">
<span class="show-for-sr">First slide details.</span>
<span class="show-for-sr" data-slide-active-label>Current Slide</span>
</button>';
$i++;
}
?>
</nav>
</div>
code below is to slide thumbnail images traverse from first to last and return to first as above but with thumbnails that show product slide 4-5 at one go. Below code must show 4-5 thumbnails with small text and traverse as timer and button click play a role.
<div class="ecommerce-product-slider orbit" role="region" aria-label="Favorite Space Pictures" data-orbit>
<ul class="orbit-container">
<button class="orbit-previous"><span class="show-for-sr">Previous Slide</span>◀︎</button>
<button class="orbit-next"><span class="show-for-sr">Next Slide</span>▶︎</button>
<?php
foreach($sectorsandcourses as $sectorandcourse){
echo '<li class="orbit-slide">
<div class="row small-up-2 medium-up-4 large-up-5 align-center">
<div class="column">
<div class="product-card">
<div class="product-card-thumbnail">
<a href="#" class="th">'.
$this->Html->image($sectorandcourse['image'], ['alt'=>'Image for sector and courses',
'style'=>'width:100%;']).'</a>
</div>
<h2 class="product-card-title">'.$sectorandcourse['sectors_and_courses'].'</h2>
<span class="product-card-desc">Product Description</span>
<span class="product-card-price">'.$sectorandcourse['count'].'</span>
</div>
</div>
</div>
</li>';
}
?>
</ul>
<nav class="orbit-bullets">
<?php
foreach($sectorsandcourses as $sectorandcourse){
echo '
<button class=data-slide="0">
<span class="show-for-sr">First slide details.</span><span class="show-for-sr">Current Slide</span>
</button>';
}
?>
</nav>
</div>
so both are different do not get confused be kind to put forward a relation between both but not to confuse them as same since one is a full screen slide show next one is thumbnail slideshow.
vision to make :
fullscreen slideshow
thumbnail slide show
Is your question the following?
i only require to work with that code that works to enable slide show beyond seond slide and return to first slide
If so please shorten your complete question to this (loop, start with first slide after last).
This already works by default as data-infinite-wrap is true by default.
https://get.foundation/sites/docs/orbit.html
https://get.foundation/sites/docs/orbit.html#js-options
You did not specify the exact Foundation version (6.x.y, x and y are needed) and we would need a https://codepen.io to see your actual problem.
Also try to remove is-active from your output. This may be the cause. And only provide generated html code so that we can reproduce your issue.
Orbit has been discontinued i suggest use carousel with bootstrap.

Why Isnt js / jquery Events working in PHP foreach

I understand foreach but this is new for me because within the foreach in PHP I have some script for each item that shows up and wondering why it only works for the item in the first item
In the code, I am getting an image from an MYSQL database. instead of using onclick in js I am learning more into jquery and only when I click the first image it will generate the
$("#main").load("includes/product.php");
path and change I want to change but in the product name and the cart button do not change the visuals.
<section id="new-products" class="clearfix">
<div class="title-block">
<h4>New Products</h4>
</div>
<?PHP
foreach ($item as $items){
?>
<div class="left-col-block">
<article class="product-box clearfix">
<a href="#store/category/<?PHP echo $items['category'];?>/<?PHP echo $items['brand'];?>/<?PHP echo $items['name'];?>" id="product-link">
<img src="<?PHP echo $items['image']; ?>" alt="Card Games" title="Card Games" height="80" width="80">
</a>
<?PHP echo $items['name']; ?><br>
<span class="price">$<?php echo $items['price'];?></span>
</article>
`<script>
$( "#product-link" ).click(function() {
$("#main").load("includes/product.php");
});
</script>
</div>
<div class="left-col-block">
</div>
<?PHP
}
?>
</section>
Expected:
I am wanting each link with the id of product-link to give the event trigger with jquery on each product and each id
Actual Results:
$("#main").load("includes/product.php");
only works on the first id that is equal to product-link
because of you have 3 like for each item and you want to set on click for every 3 link, you must use class attribute and set it unique for each item.
I changed your code to this:
<section id="new-products" class="clearfix">
<div class="title-block">
<h4>New Products</h4>
</div>
<?PHP
foreach ($item as $key=>$items){
?>
<div class="left-col-block">
<article class="product-box clearfix">
<a href="#store/category/<?PHP echo $items['category'];?>/<?PHP echo $items['brand'];?>/<?PHP echo $items['name'];?>" class="product-link-<?=$key?>">
<img src="<?PHP echo $items['image']; ?>" alt="Card Games" title="Card Games" height="80" width="80">
</a>
<?PHP echo $items['name']; ?><br>
<span class="price">$<?php echo $items['price'];?></span>
</article>
`<script>
$( ".product-link-<?=$key?>" ).click(function() {
$("#main").load("includes/product.php");
});
</script>
</div>
<div class="left-col-block">
</div>
<?PHP
}
?>
</section>
Found the answer was
<script>$( ".product-box a" ).click(function() {
$("#main").load("includes/product.php");
});</script>
since product-bot was a class and I didn't realize the # makes it check for id and the. makes it search for a class and class is able to be called multiple times whereas an id has to be unique

how to i passing row from mysql database into div popup via using javascript or jquery

i need help to passing row from mysql database into div popup window?
how do i passing product id into popup div which i called through View?
For Example I Want Like This
i want to fetch product details into `product quick view popup window`
through product `ID`?
Here My Code
<div class="latest_products_sec">
<div class="latest_products">
<div class="title_box">
</div>
<!--Latest Products Slider -->
<div class="latest_pro_box">
<h4>Latest Shirt's Collection</h4>
<div class="latest_products_slider">
<?php
$queryshirt=mysql_query("select image,id from products
where cid='1' LIMIT 5") or die ('die shirt query');
while($rowshirt=mysql_fetch_array($queryshirt))
{
echo '<ul>';
echo '<li><img src="admin/'.$rowshirt['image'].'"
width="225" height="300" alt="" />
View</li>';
echo '</ul>';?>
}
?>
#shirt Div Popup Window
<div id="shirt" class="proquickview">
<span class="close_btn" onclick="parent.jQuery.fancybox.close();">Close</span>
<h2 class="title">quick view</h2>
<div class="quickviewinfo">
<?php
// I Need To Get ID Here
echo $id=$_REQUEST['id'];
?>
<div class="quickviewinforight">
<div class="titlerow">
<h2>Latest Shirt's Collection</h2>
<div class="start_ratings">
<div class="start_rating">
</div>
</div>
<div>
<div class="quick_review">
<h3>Quick Discription</h3>
<p>TEST.</p>
</div>
<div class="qty_row">
<div class="qty_field">
<label>Select Quantity</label>
<span>
<select name="S">
<option>5</option>
</select>
</span>
</div>
<br class="clear" />
<span class="total_price">Price <strong>$88.00</strong>
<del>$102.00</del></span>
ADD TO CART
</div>
<div class="total_price_row">
</div>
</div>
</div>
</div>
Javascript For Popup Window
$(document).ready(function() {
$(".view_btn").fancybox({
'titlePosition' : 'inside',
'transitionIn' : 'none',
'transitionOut' : 'none'
});
});
$(document).ready(function(){
// Cufon Functions //
Cufon.replace ('.latest_products_slider ul li a.view_btn',{hover:true});
});
It's hard to tell what is wrong as you have only given part of the story.
Fundamentally you need:
Action by the user (usually a click) triggers AJAX call sending a unique ID onclick="updatefunction(this.id) in a SPAN or DIV will do the trick:
<SPAN onclick="updatefunction(this.id)" id="1234">Your Stuff to update</SPAN>
The JS function updatefunction must send the detail/ID to a separate PHP script (you can use the original but this just makes it clunky) which queries your database on the ESCAPED data you send.
Once the data is ready, the JS will update the window/pop it up.
AFAICS you are missing the extra bit that actually does the querying or not applying a suitable onclick.
Why not have a look at the excellent W3Schools Ajax tutorial - it will help though does not use jQuery.

Display Terms of service in any place (Joomla/Virtuemart 2.x)

I have some toruble with displaying terms of service.
At the cart page all works fine: http://mtxt.ibroken.ru/component/virtuemart/cart.html?Itemid=0
(bottom link) opens popup with text, generated by
<?php echo $this->cart->vendor->vendor_terms_of_service; ?>
code.
But i have button on the shop page http://mtxt.ibroken.ru/magazin.html (top button at right side), which must display same text...
At present moment text written in /modules/mod_virtuemart_cart/tmpl/default.php file. But how to get it in this file from shop interface by using PHP?
pps. Ugly English, sorry for that :)
You need to modify /modules/mod_virtuemart_cart/tmpl/default.php (or your override) and add this code just after line 3:
vmJsApi::js ('facebox');
vmJsApi::css ('facebox');
$document = JFactory::getDocument ();
$document->addScriptDeclaration ("
jQuery(document).ready(function($) {
$('div#full-tos').hide();
$('a#terms-of-service').click(function(event) {
event.preventDefault();
$.facebox( { div: '#full-tos' }, 'my-groovy-style');
});
});
");
And add this code just after line 53
<div class="show_cart">
<?php
if(!class_exists('VirtueMartModelVendor'))
require(JPATH_VM_ADMINISTRATOR.DS.'models'.DS.'vendor.php');
$vendor = VmModel::getModel('vendor');
$vendor = $vendor->getVendor();
?>
<br />
<span style="z-index: 0;">
<a href="<?php JRoute::_ ('index.php?option=com_virtuemart&view=vendor&layout=tos&virtuemart_vendor_id=1') ?>" class="terms-of-service" id="terms-of-service" rel="facebox" target="_blank">
<?php echo JText::_ ('COM_VIRTUEMART_CART_TOS_READ_AND_ACCEPTED'); ?>
</a>
</span>
<div id="full-tos">
<h2><?php echo JText::_ ('COM_VIRTUEMART_CART_TOS'); ?></h2>
<?php echo $vendor->vendor_terms_of_service; ?>
</div>
</div>
That shoud do the trick!

Categories