PDA

View Full Version : Animated Collapsible DIV v2.4 cant use variable as anchor



Dahls
06-28-2013, 02:58 PM
1) Script Title: Animated Collapsible DIV v2.4

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/animatedcollapse.htm

3) Describe problem: i have php variable {featured.ID} it generate number for each of my items 1 2 3 etc

so i tried in java setting it up as

animatedcollapse.addDiv('item{featured.ID}','speed=1,fade=0,persist=0,hide=1')

and in div as

"javascript:animatedcollapse.toggle('item{featured.ID}')"></a> <a href="javascript:animatedcollapse.hide('item{featured.ID}')"></a></span></a></span>
<div id="item{featured.ID}" style="display:none;" class="infobox">

then when click my link it says item1 and item2 for my two items but they only expand if i call the java for 'item1' and 'item2' instead of 'item{featured.ID}' as there will be hundreds if items i cant just call them item1 item2 item3 etc need the script to use my variable.

btw great code im also using it here http://dahlsvarehus.dk you can see it in the ? mark icon in user login and in the icons in news and in the currency calculator section
the places it is not work is the eye icons i have set one of the eyes to work by make code called ´item2´ just for testing

jscheuer1
06-28-2013, 03:21 PM
That's not valid PHP code unless the entire string is in double quotes, and even if it is it would have to be being written server side, and featured.ID would have to be defined. If it's not double quoted and written by the server, it would have to be something like:


animatedcollapse.addDiv('item<php echo featured.ID; ?>','speed=1,fade=0,persist=0,hide=1')

In other words, you haven't shown enough of the PHP code for me to tell. I'm not seeing any error notices in the served source code though. But you might have them turned off. Or feastured.ID may be resolving to a blank string.

What I do see is:


<script type="text/javascript">
animatedcollapse.addDiv('jason', 'fade=1,height=80px')
animatedcollapse.addDiv('kelly', 'fade=1,height=100px')
animatedcollapse.addDiv('shownews','speed=1,fade=0,persist=0,hide=1')
animatedcollapse.addDiv('showforgot','speed=1,fade=0,persist=0,hide=1')
animatedcollapse.addDiv('showcurrency','speed=1,fade=0,persist=0,hide=1')
animatedcollapse.addDiv('item','speed=1,fade=0,persist=0,hide=1')
animatedcollapse.addDiv('item2','speed=1,fade=0,persist=0,hide=1')
animatedcollapse.addDiv('cat', 'fade=0,speed=400,group=pets')
animatedcollapse.addDiv('dog', 'fade=0,speed=400,group=pets,persist=1,hide=1')
animatedcollapse.addDiv('rabbit', 'fade=0,speed=400,group=pets,hide=1')
animatedcollapse.ontoggle=function($, divobj, state){ //fires each time a DIV is expanded/contracted
//$: Access to jQuery
//divobj: DOM reference to DIV being expanded/ collapsed. Use "divobj.id" to get its ID
//state: "block" or "none", depending on state
}
animatedcollapse.init()
</script>



So, if that's (the highlighted line) where you have:


animatedcollapse.addDiv('item{featured.ID}','speed=1,fade=0,persist=0,hide=1')

it's not resolving on the server side.

Dahls
06-28-2013, 03:35 PM
here is my featured id code

// get featured items
$query = "SELECT id, title, current_bid, pict_url, ends, num_bids, minimum_bid, bn_only, description, shipping_cost, shipping_terms, buy_now
FROM " . $DBPrefix . "auctions
WHERE closed = 0 AND suspended = 0 AND starts <= " . $NOW . "
AND featured = 'y'
ORDER BY RAND() DESC LIMIT 12";
$res = mysql_query($query);
$system->check_mysql($res, $query, __LINE__, __FILE__);

$i = 0;
while($row = mysql_fetch_assoc($res))
{
$ends = $row['ends'];
$difference = $ends - time();
if ($difference > 0)
{
$ends_string = FormatTimeLeft($difference);
}
else
{
$ends_string = $MSG['911'];
}
if ($row['buy_now'] > 0 && $row['bn_only'] == 'n' && ($row['num_bids'] == 0 || ($row['reserve_price'] > 0 && $row['current_bid'] < $row['reserve_price'])))
{
$row['buy_now'] = ' ' . $system->print_money($row['buy_now']) . '';
}
elseif ($row['buy_now'] > 0 && $row['bn_only'] == 'y')
{

}
else
{

$row['buy_now'] = '';
}
$high_bid = ($row['num_bids'] == 0) ? $row['minimum_bid'] : $row['current_bid'];
$template->assign_block_vars('featured', array(
'AUCTION_DESCRIPTION' => $row['description'],
'SHIPPING_COST' => $row['shipping_cost'],
'SHIPPING_TERMS' => $row['shipping_terms'],
'ENDS' => $ends_string,
'DIFFERENCE'=> $difference,
'BUY_NOW' => ($row['buy_now'] == 'y'),
'ID' => $row['id'],
'BID' => $system->print_money($high_bid),
'BUY_NOW' => ($difference < 0) ? '' : $row['buy_now'],
'IMAGE' => (!empty($row['pict_url'])) ? 'getthumb.php?w=' . $system->SETTINGS['thumb_show'] . '&amp;fromfile=' . $uploaded_path . $row['id'] . '/' . $row['pict_url'] : 'images/email_alerts/default_item_img.jpg',
'TITLE' => $row['title']
));
}

jscheuer1
06-28-2013, 04:07 PM
I don't see any:


animatedcollapse.addDiv

in there. And I don't know enough about PHP and mysql to really follow what you have there. I'm pretty good at PHP, it's mysql that I'm unfamiliar with.

But it looks like feadured.ID is somehow a property of $template, so to get it, you might have to reference it as a property of $template. But, as I say I'm not all that familiar with the mysql part of the code. I do know that featured.ID, however it's accessed, must be defined as expected at the time you tell the server to write it. And that the way you tell the server to write it into the animatedcollapse.addDiv function must be valid PHP, and happen at a point on the page where it will fit into the javascript code in the required spot.

The good news is that this:


<script type="text/javascript">
animatedcollapse.addDiv('jason', 'fade=1,height=80px')
animatedcollapse.addDiv('kelly', 'fade=1,height=100px')
animatedcollapse.addDiv('shownews','speed=1,fade=0,persist=0,hide=1')
animatedcollapse.addDiv('showforgot','speed=1,fade=0,persist=0,hide=1')
animatedcollapse.addDiv('showcurrency','speed=1,fade=0,persist=0,hide=1')
animatedcollapse.addDiv('item','speed=1,fade=0,persist=0,hide=1')
animatedcollapse.addDiv('item2','speed=1,fade=0,persist=0,hide=1')
animatedcollapse.addDiv('cat', 'fade=0,speed=400,group=pets')
animatedcollapse.addDiv('dog', 'fade=0,speed=400,group=pets,persist=1,hide=1')
animatedcollapse.addDiv('rabbit', 'fade=0,speed=400,group=pets,hide=1')
animatedcollapse.ontoggle=function($, divobj, state){ //fires each time a DIV is expanded/contracted
//$: Access to jQuery
//divobj: DOM reference to DIV being expanded/ collapsed. Use "divobj.id" to get its ID
//state: "block" or "none", depending on state
}
animatedcollapse.init()
</script>



Can go almost anywhere on the page after the main collapsible script. And that instead of one big block of them you can have separate:


<script type="text/javascript">
animatedcollapse.addDiv('item<php echo featured.ID; ?>','speed=1,fade=0,persist=0,hide=1')
</script>



throughout the page as long as at the end of the page you do (right before the closing </body> tag):


<script type="text/javascript">
animatedcollapse.init()
</script>



Sorry I cannot be of more help.

Dahls
06-28-2013, 04:25 PM
you pointed me in the right direction, moving the script was the solution, after i placed it inside the <!-- BEGIN featured --> it was solved :)

<!-- BEGIN featured -->
<script type="text/javascript">
animatedcollapse.addDiv('item{featured.ID}','speed=1,fade=0,persist=0,hide=1')
</script>

rest of my code ....
<!-- END featured -->

Thank you mate :)