Pass dynamic variables to Javascript function? [duplicate] - php

This question already has answers here:
How do I pass variables and data from PHP to JavaScript?
(19 answers)
Closed 8 years ago.
<?php if ($option['type'] == 'select') { ?>
<div id="option-<?php echo $option['product_option_id']; ?>" class="option">
<?php if ($option['required']) { ?>
<span class="required">*</span>
<?php } ?>
<b><?php echo $option['name']; ?>:</b><br />
<select name="option[<?php echo $option['product_option_id']; ?>]">
<!-- <option value=""><?php echo $text_select; ?></option> -->
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
<?php } ?>
</option>
<?php } ?>
</select>
<?php if ($option_value['image'] != 'image/' && $option_value['image'] != 'image/no_image.jpg' ) { ?><?php
list($simgwidth) = getimagesize($option_value['image']);
$selectimgpos = $simgwidth + 35;
?>
<center>
<span id="img<?php echo $option['product_option_id']; ?>" style="position: absolute; display: none; left: -<?php echo $selectimgpos; ?>px; background: #eee; padding: 10px; border: 1px dotted #666; z-index: 90;">
<img src="<?php echo $option_value['image']; ?>">
<br /><strong><?php echo $option['name']; ?></strong>
</span></center><?php } ?>
</div>
<br />
<?php } ?>
Hi, I am new to programming and I need help with the above section of code. Normally this code just displays a Select dropdown box with options.
I've modified it by adding an extra image at the bottom inside a span. I've also calculated the width and repositioned the image based on its -width.
What I'd like to do next is have a javascript where if the user hovers or onFocus on the Select box will show the image inside the span. And if they change the select box, the image will change based on what they selected. I'm thinking onBlur to hide the pic after.
I've found some javascripts to do this but I need to pass dynamic variables from the php.
I found this javascript, but the code doesn't let me pass variables.
<script type="text/javascript">
function swapImage(){
var image = document.getElementById("imageToSwap");
var dropd = document.getElementById("dd");
image.src ="images/"+dropd.value+".jpg";
};
</script>
Due to constantly changing IDs generated by php I can't be using static variables.
Any help would be appreciated. Thanks all.
PS: $option_value['image'] is a php array. How can I display the first or last element in this array? Normally it's something like array_[n] but this one already has brackets? $option_value['image[0]'] ??

To pass php variable to javascript, you just need to echo them out in the right place:
// in your php file
<?php
$image_to_swap = "my_id_of_image_to_swap";
$element = "my_id_of_element";
?>
<script type="text/javascript">
function swapImage(){
var image = document.getElementById("<?php echo $image_to_swap; ?>");
var dropd = document.getElementById("<?php echo $element; ?>");
image.src ="images/"+dropd.value+".jpg";
};
</script>
As for your PS:
PHP arrays can be multidimensional, so for the following array:
$image = array(
0 => array(
0 => 'apple',
1 => 'banana'
),
1 => array(
0 => 'broccoli',
1 => 'cauliflower'
),
2 => array(
0 => 'peanut',
1 => 'walnut'
)
);
You can access the items as:
echo $image[0][0]; // outputs apple
echo $image[2][1]; // outputs walnut
And you can use strings as keys, so you could also name your keys and access them with strings:
$image = array(
'fruits' => array(
0 => 'apple',
1 => 'banana'
),
'vegetables' => array(
0 => 'broccoli',
1 => 'cauliflower'
),
'nuts' => array(
0 => 'peanut',
1 => 'walnut'
)
);
You can access the items as:
echo $image['fruits'][0]; // outputs apple
echo $image['nuts'][1]; // outputs walnut

Related

Magento: Display Product Options in Product Page as List Elements in Two Columns

Having actual Magento 1.9.3 situation...
In product-page there are a lot of configuration options. Need to save space, so need to turn the one column vertical product options list into a two column list to reduce the space to 50%.
Already tried several methods, also this one:
https://magento.stackexchange.com/questions/70857/display-product-options-change-layout-of-in-block-after-info-column
in combination with
Css Styling list elements in two columns
and this
https://csswizardry.com/2010/02/mutiple-column-lists-using-one-ul/
But did not figure it out really. Was stopping on the results, to display all in only one horizontal line. The issue is, that if there are 10 attributes to select, the line is becoming very pressed and nothing is recognisable.
Is anyone out there, who is able to adjust the code?
Here is the code having in:
/template/catalog/product/view/type/options/configurable.phtml
<?php
$_product = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
$_jsonConfig = $this->getJsonConfig();
$_renderers = $this->getChild('attr_renderers')->getSortedChildren();
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
<div class="items">
<dl>
<?php foreach($_attributes as $_attribute): ?>
<?php
$_rendered = false;
foreach ($_renderers as $_rendererName):
$_renderer = $this->getChild('attr_renderers')->getChild($_rendererName);
if (method_exists($_renderer, 'shouldRender') && $_renderer->shouldRender($_attribute, $_jsonConfig)):
$_renderer->setProduct($_product);
$_renderer->setAttributeObj($_attribute);
echo $_renderer->toHtml();
$_rendered = true;
break;
endif;
endforeach;
if (!$_rendered):
?>
<dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>
<dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
</div>
</dd>
<?php endif; ?>
<?php endforeach; ?>
</dl>
</div>
<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $_jsonConfig ?>);
</script>
<?php echo $this->getChildHtml('after') ?>
<?php endif;?>
Without Seeing the output its hard to know what you want exactly, but if you want the options to be in 2 columns this should work.
.items dl {
display:flex;
flex-wrap: wrap;
}
.items dl .options-wrapper{
width: 50%;
}
//If you want on smaller screens to make them 1 row.
#media screen and (max-width: 768px) {
.items dl .options-wrapper{
width: 100%;
}
}
<?php
$_product = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
$_jsonConfig = $this->getJsonConfig();
$_renderers = $this->getChild('attr_renderers')->getSortedChildren();
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
<div class="items">
<dl>
<?php foreach($_attributes as $_attribute): ?>
<?php
$_rendered = false;
foreach ($_renderers as $_rendererName):
$_renderer = $this->getChild('attr_renderers')->getChild($_rendererName);
if (method_exists($_renderer, 'shouldRender') && $_renderer->shouldRender($_attribute, $_jsonConfig)):
$_renderer->setProduct($_product);
$_renderer->setAttributeObj($_attribute);
echo $_renderer->toHtml();
$_rendered = true;
break;
endif;
endforeach;
if (!$_rendered):
?>
<div class="options-wrapper">
<dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>
<dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
</div>
</dd>
</div>
<?php endif; ?>
<?php endforeach; ?>
</dl>
</div>
<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $_jsonConfig ?>);
</script>
<?php echo $this->getChildHtml('after') ?>
<?php endif;?>

Change select value when changing another select

I got 3 array's where from i make 2 select box and a checkbox. What i want to do is that when i change CMS the checkbox value needs to change like in the array.
if i choose Joomla in the select box then i want the checkbox that is made with the $aOnderdelen, then in the array $aOnderdelen i have an array with Contact-form Foto-gallery and Carousel and this 3 have an array with the name of each CMS with different values and this are the values that the checkbox needs to get when you choose one of those and the CMS.
Example: i choose Joomla and i choose a Contact-formulier than contact-formulier checbox gets 3 as value.
$aCMS = array('SilverbeeCMS','Joomla','WP','Drupal','Scott');
$prijsPerUur=1;
$basisPrijs=
array(
array('titel' => 'Kopie', 'uur' => '8'),
array('titel' => 'Maatwerk', 'uur' => '10'),
array('titel' => 'Aangekocht', 'uur' => '12'),
array('titel' => 'Custom', 'uur' => '14')
);
$aOnderdelen = array
(
'Contact-formulier' => array
(
'SilverbeeCMS'=>3,
'WP'=>2,
'Joomla'=>3,
'Drupal'=>4,
'Scott'=> 5
),
'Foto-gallery' => array
(
'SilverbeeCMS'=>1,
'WP' => 3,
'Joomla'=> 4,
'Drupal'=> 5,
'Scott'=> 6
),
'Carousel' => array
(
'SilverbeeCMS'=>1,
'WP' => 4,
'Joomla'=> 5,
'Drupal'=> 6,
'Scott'=> 7
)
);
?>
This is the HTML form where the Select and checkbox are
<form action="" method="post">
<select id="cms" class="form-control" name="cms">
<?php foreach($aCMS as $key => $value): ?>
<option value="<?php echo strtolower($aCMS[$key]); ?>">
<?php echo $aCMS[$key]; ?>
</option>
<?php endforeach; ?>
</select>
<label><?php echo $template.$verplicht; ?></label>
<select id="templates" class="form-control" name="templates">
<?php foreach($basisPrijs as $key => $value): ?>
<option value="<?php echo $basisPrijs[$key]["uur"]; ?>">
<?php echo $basisPrijs[$key]["titel"]; ?>
</option>
<?php endforeach; ?>
</select>
<?php echo $oTitel; ?>
<div class="checkbox col-xs-12">
<div class="row">
<?php foreach($aCMS as $cmsKey => $cmsValue) ?>
<?php foreach($aOnderdelen as $key => $value):
foreach($value as $key1 => $value1)
{};
$i++;
echo "<div class='checkbox'>
<label><input class='check".$i."' type='checkbox' value='".strtolower($key)."' name='".$key."'>".$key."</label></div>"
;endforeach;?>
</div>
</div>
</form>
You have to use jquery along with AJAX for changing things dynamically
Simple example as
$(document).ready(function() {
$('#selector').change(function() {
//do here things required about changing
//You can also change DOM elements according to needs
//and have Ajax requests
})
});
I found how to do it
switch($("option:selected").val())
{
case "silverbeecms":
$(".check1").val(<?php echo $aOnderdelen["Contact-formulier"]["SilverbeeCMS"] ?>)
$(".check2").val(<?php echo $aOnderdelen["Foto-gallery"]["SilverbeeCMS"] ?>)
$(".check3").val(<?php echo $aOnderdelen["Carousel"]["SilverbeeCMS"] ?>)
break;
case "joomla":
$(".check1").val(<?php echo $aOnderdelen["Contact-formulier"]["Joomla"] ?>)
$(".check2").val(<?php echo $aOnderdelen["Foto-gallery"]["Joomla"] ?>)
$(".check3").val(<?php echo $aOnderdelen["Carousel"]["Joomla"] ?>)
break;
case "wp":
$(".check1").val(<?php echo $aOnderdelen["Contact-formulier"]["WP"] ?>)
$(".check2").val(<?php echo $aOnderdelen["Foto-gallery"]["WP"] ?>)
$(".check3").val(<?php echo $aOnderdelen["Carousel"]["WP"] ?>)
break;
case "drupal":
$(".check1").val(<?php echo $aOnderdelen["Contact-formulier"]["Drupal"] ?>)
$(".check2").val(<?php echo $aOnderdelen["Foto-gallery"]["Drupal"] ?>)
$(".check3").val(<?php echo $aOnderdelen["Carousel"]["Drupal"] ?>)
break;
case "scott":
$(".check1").val(<?php echo $aOnderdelen["Contact-formulier"]["Scott"] ?>)
$(".check2").val(<?php echo $aOnderdelen["Foto-gallery"]["Scott"] ?>)
$(".check3").val(<?php echo $aOnderdelen["Carousel"]["Scott"] ?>)
break;
}
New Answer more Flexibel
First Loop through the PHP array.
<?PHP
foreach($aCMS as $cmsKey => $cmsValue)
?>
<?php
foreach($aOnderdelen as $key => $value)
:
foreach($value as $key1 => $value1){};
?>
Than use data attr to get the prices.
<input class="<?php echo strtolower($key);?>" type="checkbox" value="<?php echo strtolower($key)?>" name="<?php echo $key;?>" data-silverbeecms="<?php echo $value['SilverbeeCMS']; ?>" data-wp="<?php echo $value['WP'];?>" data-joomla="<?php echo $value['Joomla'];?>" data-drupal="<?php echo $value['Drupal'];?>" data-scott="<?php echo $value['Scott'];?>">
After you get the Price in the data you can call this data from JQUERY and do the Match.
urenOnderdelen = 0;
$("#sCms, #templates, .contact-formulier, .foto-gallery, .carousel").change(function()
{
urenOnderdelen = 0;
urenTemplate = $("#templates").val();
$(".contact-formulier, .foto-gallery, .carousel").each(function()
{
if(this.checked)
{
urenOnderdelen+=parseInt($(this).data($("option:selected").val()));
}
});
$("#output, #output1, #gVoor").hide().fadeIn(300);
urenTemplate = $("#templates").val();
urenTemplate = parseInt(urenTemplate);
urenOnderdelen = parseInt(urenOnderdelen);
totaal = urenOnderdelen + urenTemplate;
$("#output").text(euroTeken + totaal*prijs);
});

PHP quiz - display correct and incorrect answers

I have a php quiz script that I have been using and am trying to modify it to display both correct and incorrect answers and am having issues trying to accomplish this.
So when a user selects the incorrect answer, I want the script to display the incorrect answer and then the correct answer below it. I have figure out how to display the letter of the correct answer, but I want the actual answer to be displayed and not just the letter.
I am a beginner with php so any help would be appreciated.
Here is the entire code:
<?php get_header();
/*
Template Name: PHP Quiz safety asmnt
*/
$Questions = array(
1 => array(
'Question' => 'The appropriate response during a health threatening emergency such as a fire or toxic spill is to:',
'Answers' => array(
'A' => 'Pull the fire alarm; evacuate immediately to the assemply point; and do not re-enter the cleanroom until instructed to do so.',
'B' => 'Notify lab; evacuate immediately to the assemply point; and do not re-enter the cleanroom until instructed to do so.',
'C' => 'Call EH&S'
),
'CorrectAnswer' => 'A'
),
2 => array(
'Question' => 'With proper use of wet bench and disposal procedures, the laboratory should be free of odors. In general, if you smell something, you should:',
'Answers' => array(
'A' => 'Call EH&S; Clear affected area if necessary; Notify staff and other users',
'B' => 'Do nothing; odd smells are normal when working in the cleanroom.',
'C' => 'Notify staff member; clear affected area; wait for instruction from staff who will investigate'
),
'CorrectAnswer' => 'C'
)
);
?>
<div id="bodyPage" class="clear">
<!------- start body ------->
<section id="contentPage">
<h1 class="title"><?php the_title(); ?></h1>
<?php
if (isset($_POST['answers'])){
$Answers = $_POST['answers']; // Get submitted answers.
echo '<br />';
// Automated question checking!)
foreach ($Questions as $QuestionNo => $Value){
// Echo the question
echo $QuestionNo. '. ' .$Value['Question'].'<blockquote>';
if ($Answers[$QuestionNo] != $Value['CorrectAnswer']){
echo 'You entered incorrectly:<br />'.'<span style="color: red;">'.$Value['Answers'][$Answers[$QuestionNo]].'</span>';
echo '<br/>'.'The correct answer is:<br />'.'<span style="color: green;">'.$Value['CorrectAnswer'][$Answers[$QuestionNo]].'</span>';
} else {
echo 'You entered correctly:<br />'.'<span style="color: green;">'.$Value['Answers'][$Answers[$QuestionNo]].'</span>';
}
echo '</blockquote>';
}
} else {
?>
<form action="<?php the_permalink(); ?>" method="post" id="quiz">
<ol>
<?php foreach ($Questions as $QuestionNo => $Value){ ?>
<li>
<h4><?php echo $Value['Question']; ?></h4>
<?php
foreach ($Value['Answers'] as $Letter => $Answer){
$Label = 'question-'.$QuestionNo.'-answers-'.$Letter;
?>
<div>
<input type="radio" name="answers[<?php echo $QuestionNo; ?>]" id="<?php echo $Label; ?>" value="<?php echo $Letter; ?>" />
<label for="<?php echo $Label; ?>"><!--<?php echo $Letter; ?>)--> <?php echo $Answer; ?> </label>
</div>
<?php } ?>
</li>
<?php } ?>
</ol>
<input type="submit" value="Submit Quiz" />
</form>
<?php
}
?>
<!------- end body ------->
</div>
<?php get_footer(); ?>
A little late but here's one way:
foreach ($Questions as $QuestionNo => $Value){
// Echo the question
echo $Value['Question'].'<br />';
if ($Answers[$QuestionNo] != $Value['CorrectAnswer']){
echo '<span style="color: red;">'.$Value['Answers'][$Answers[$QuestionNo]].'</span>'; // Replace style with a class
} else {
echo '<span style="color: green;">'.$Value['Answers'][$Answers[$QuestionNo]].'</span>'; // Replace style with a class
}
echo '<br /><hr>';
}
(taken from: PHP quiz with on screen results )
Try this:
foreach( $Questions as $QuestionNo => $Value ) {
echo $QuestionNo . '. ' . $Value['Question'].'<blockquote>';
if( $Answers[$QuestionNo] != $Value['CorrectAnswer'] ) {
echo 'You entered incorrectly:<br />'.'<span style="color:red;">'.$Value['Answers'][$Answers[$QuestionNo]].'</span>';
echo '<br/>'.'The correct answer is:<br />'.'<span style="color: green;">'.$Value['Answers'][$Answers[$QuestionNo]].'</span>';
} else {
echo 'You entered correctly:<br />'.'<span style="color: green;">'.$Value['Answers'][$Answers[$QuestionNo]].'</span>';
}
echo '</blockquote>';
}

Change SKU on select product size Magento [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Change Add to cart button to Preorder on select
I have a small issue with my script to select the sku of every product on select.
The issue is that, if i add 2 drop-down options the jquery is matching the same id twice.
But if i have only 1 drop-down with color or size, the sku is mapping showing correctly.
My question is... how can i get the correct sku for the second color ?
<?php
$_product = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
<dl>
<?php foreach($_attributes as $_attribute): ?>
<dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>
<dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select"
onchange="return changeSku(<?php echo $_attribute->getAttributeId() ?>, this);">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
</div>
</dd>
<?php endforeach; ?>
</dl>
<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
</script>
<div id="sku-container"></div>
<?php
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
$productMap = array();
foreach($col as $simpleProduct){
$productMap[$simpleProduct->getId()] = $simpleProduct->getAttributeText('sku');
}
?>
<script type="text/javascript">
document.observe("dom:loaded", function() {
$("sku-container").update("<strong>SKU: </strong> ...");
});
function changeSku(confAttributeId, sel) {
var productMap = <?php echo Mage::helper('core')->jsonEncode($productMap);?>;
var selectedAttributeId = sel.options[sel.selectedIndex].value;
if (selectedAttributeId) {
var options = spConfig.config.attributes[confAttributeId].options;
var productId = options.find(function (option) {return option.id == selectedAttributeId}).products[0]
$("sku-container").update("<strong>SKU: </strong>" + productMap[productId]);
} else {
$("sku-container").update("<strong>SKU: </strong> ...");
}
}
</script>
spConfig Result: var spConfig = new Product.Config({"attributes":{"80":{"id":"80","code":"color","label":"Color","options":[{"id":"42","label":"Blue","price":"0","oldPrice":"0","products":["6873","6874"]},{"id":"46","label":"Green","price":"0","oldPrice":"0","products":["6881","6882","6883","6884","6885"]}]},"123":{"id":"123","code":"size","label":"Size","options":[{"id":"13","label":"4 UK","price":"0","oldPrice":"0","products":["6881"]},{"id":"12","label":"4.5 UK","price":"0","oldPrice":"0","products":["6873","6882"]},{"id":"11","label":"5 UK","price":"0","oldPrice":"0","products":["6874","6883"]},{"id":"10","label":"5.5 UK","price":"0","oldPrice":"0","products":["6884"]},{"id":"9","label":"6 UK","price":"0","oldPrice":"0","products":["6885"]}]}},"template":"#{price}\u00a0USD","basePrice":"489","oldPrice":"489","productId":"9844","chooseText":"Select\u0163i o op\tion...","taxConfig":{"includeTax":true,"showIncludeTax":true,"showBothPrices":false,"defaultTax":24,"currentTax":24,"inclTaxTitle":"Whit tax"}});
Any help is appreciated.
Issue resolved by SCP Simple Configurable Product. made by Organic Internet.
Link to Extension

JQuery + Wordpress PHP variable

I'm using the jquery cycle to create a slideshow in my Wordpress template. The "pager" is creating buttons that overlay the slideshow and rollover advances the slides. The trouble I'm running into is that I need the rollover to stay the same, but I also need to set an href so that clicking on the buttons takes the user to a specific page.
I need to retrieve the variable $target from my slideshow for the href.
I need the onclick to make the button clickable.
As I stated above, I'm new at this and it's quite possible that this is terrible code/can't be done/I'm a moron.
My jquery:
<script src="<?php bloginfo('stylesheet_directory'); ?>/scripts/jquery.cycle.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
if ( $('.slides > .slide').size() > 1 ) {
$('.slides')
.cycle({
timeout: 6000,
speed: 1000,
pager: '#slides #mainNav',
pauseOnPagerHover: 200,
pagerEvent: 'mouseover',
pause: true,
pagerAnchorBuilder: function(idx, slide) {
var slideImage = $(slide).find('img');
var slideTitle = slideImage.attr('title');
var slideURL = "<?php echo $target; ?>";
return '<li>' + slideTitle + /* '<br /><span class="description">' + slideDescr + '</span>*/'</li>';
}
});
}
});
</script>
and my Wordpress slideshow:
<?php if ( is_front_page() && $slides = get_posts(array('numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'slide')) ) : ?>
<div id="mainImg">
<div id="slides">
<div class="slides">
<?php foreach ($slides as $slide) : ?>
<?php $title = $slide->post_title; ?>
<?php $content = wpautop($slide->post_content); ?>
<?php $description = get_post_meta($slide->ID, 'description', true); ?>
<?php $thumb = get_the_post_thumbnail($slide->ID, 'slide', array('title' => $title, 'alt' => $description)); ?>
<?php $url = get_post_meta($slide->ID, '_slide_url', true); ?>
<?php $target = (get_post_meta($slide->ID, '_slide_url_blank', true)) ? 'target="_blank"' : ''; ?>
<div class="slide">
<?php if ($url) : ?>
<a href="<?php echo $url; ?>" <?php echo $target; ?>><?php echo $thumb; ?></a>
<?php else: ?>
<?php echo $thumb; ?>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<div id="mainNav"></div>
</div>
</div><!--end mainImg-->
<?php endif; ?>
Thank you in advance for your help.
Where you have:
var slideURL = "<?php echo $target; ?>"
Replace it with:
var slideURL = $(slide).find('a').attr('target');
What you are doing above is getting the slide object, finding the 'a' tag in the slide, and then getting the "target" attribute of the 'a' tag. This value is then assigned to the slideURL variable (which will either be '_blank' or undefined). For more information on how to use jQuery to get HTML elements and/or their attributes, you should familiarise yourself more with jQuery's Traversing and Attributes methods.
You should never mix Javascript code with PHP or even HTML code anyway. Read up more on "Unobtrusive JavaScript".

Categories