Forum Moderators: open

Message Too Old, No Replies

Basic javascript next button !

one step forward two step backwards?

         

tomda

9:00 pm on Nov 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I did a plugin for a CMS to make boxes fed with XML using XSLT... It was working great, did upgrade to make it better with categories, but in the upgrade the javascript Previous-Next is not working properly... And it has been like that for already 2 months, did everything to find the bug ? So still have old version uncategorised running online :(

Click the button and showVDM(1) is triggered

Click on Next and showVDM(2) is triggered

Click on Next and showVDM(3) is triggered and fully executed but then showVDM(1) is triggered again ?

Sorry for the code, it is not that long. Please note it is generated in PHP.

Thank you


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="fr-FR" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php
$vdm_cat_array[0] = array ("last", "derniers");
$vdm_cat_array[1] = array ("random", "hasard");

if(isset($_GET['vdm_count'])) {$vdm_count=$_GET['vdm_count'];} else {$vdm_count="3";}
if(!is_numeric($vdm_count) AND ($vdm_count!="1" OR $vdm_count!="5" OR $vdm_count!="15")) {$vdm_count="3";}

if(isset($_GET['vdm_type'])) {$vdm_type=$_GET['vdm_type'];} else {$vdm_type="last";}
if(!in_array($vdm_type, $vdm_cat_array)) {$vdm_type="last";}

if(isset($_GET['vdm_second'])) {$vdm_second=$_GET['vdm_second'];} else {$vdm_second="0";}
if(!is_numeric($vdm_second)) {$vdm_second="0";}

$vdm_total = "15";
$lastpage = intval($vdm_total/$vdm_count);

echo '<script language="javascript" type="text/javascript">
function showVDM(i) {
if(!i) {var i = 1;}

alert("1 - show VDM "+i);

var tmp_min = ((parseFloat(i) - 1) * '.$vdm_count.') + 1;
var tmp_max = ((parseFloat(i) - 1) * '.$vdm_count.') + '.$vdm_count.';
for (c=1; c<='.$vdm_total.'; c++) {
var contID = "vdm_id"+c;
if(c>=tmp_min && c<=tmp_max) {
if(document.getElementById(contID)) {document.getElementById(contID).style.display="block";}
} else {
if(document.getElementById(contID)) {document.getElementById(contID).style.display="none";}
}
}

document.getElementById(\'vdm_blank_page\').value=i;

alert("2 - VDM form input "+i);

if(i==1) {
var tmp=parseFloat(i)+1;
document.getElementById("vdm_pagination").style.display="block";
document.getElementById("vdm_pagination").innerHTML = "<span class=\"vdmsp vdm_re1tr\">&nbsp;</span>&#160;&#160;<span class=\"vdmsp vdm_re2tr\">&nbsp;</span>&#160;&#160;&#160;Page "+i+"/'.$lastpage.'&#160;&#160;&#160;<span class=\"vdmsp vdm_for2\" onclick=\"showVDM("+tmp+");';
if(!empty($vdm_second)) {echo ' StartVDM();';}
echo '\">&nbsp;>></span>&#160;&#160;<span class=\"vdmsp vdm_for1\" onclick=\"showVDM('.$lastpage.');';
if(!empty($vdm_second)) {echo ' StartVDM();';}
echo '\">&nbsp;</span>";
} else if (i=='.$lastpage.') {
var tmp=parseFloat(i)-1;
document.getElementById("vdm_pagination").style.display="block";
document.getElementById("vdm_pagination").innerHTML = "<span class=\"vdmsp vdm_re1\" onclick=\"showVDM(1);';
if(!empty($vdm_second)) {echo ' StartVDM();';}
echo '\">&nbsp;</span>&#160;&#160;<span class=\"vdmsp vdm_re2\" onclick=\"showVDM("+tmp+");';
if(!empty($vdm_second)) {echo ' StartVDM();';}
echo '\">&nbsp;</span>&#160;&#160;&#160;Page "+i+"/'.$lastpage.'&#160;&#160;&#160;<span class=\"vdmsp vdm_for2tr\">>>&nbsp;</span>&#160;&#160;<span class=\"vdmsp vdm_for2tr\" onclick=\"showVDM('.$lastpage.');';
if(!empty($vdm_second)) {echo ' StartVDM();';}
echo '\" >&nbsp;</span>";
} else {

alert (\'3 - else this is where the bug is, check source code of red part, it is showVDM(3) but it trigger 1 again ?\');

var tmp=parseFloat(i)+1;
var tmp2=parseFloat(i)-1;
document.getElementById("vdm_pagination").style.display="block";
document.getElementById("vdm_pagination").innerHTML = "<span class=\"vdmsp vdm_re1\" onclick=\"showVDM(1);';
if(!empty($vdm_second)) {echo ' StartVDM();';}
echo '\">&nbsp;</span>&#160;&#160;<span class=\"vdmsp vdm_re2\" onclick=\"showVDM("+tmp2+");';
if(!empty($vdm_second)) {echo ' StartVDM();';}
echo '\">&#160;&#160;&#160;Page "+i+"/'.$lastpage.'&#160;("+tmp2+"-"+tmp+")&#160;&#160;<span style=\"color:red;\" class=\"vdmsp vdm_for2\" onclick=\"showVDM("+tmp+");';
if(!empty($vdm_second)) {echo ' StartVDM();';}
echo '\">&nbsp;>></span>&#160;&#160;<span class=\"vdmsp vdm_for1\" onclick=\"showVDM('.$lastpage.');';
if(!empty($vdm_second)) {echo ' StartVDM();';}
echo '\">&nbsp;</span>";

alert(\'4 - end else \'+i);
}

alert(\'5 - end showVDM \'+i);
}';
echo '
</script>
</head>
<body>
<input type="button" onclick="javascript:showVDM(); return false;" />
<div id="vdm_pagination"></div>
<input type="text" name="vdm_blank_page" id="vdm_blank_page" />
</body>';
?>

Fotiman

11:40 pm on Nov 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You might get more help if you post the actual generated code. In other words, visit your page and do View > Source and copy that output here instead of copying the PHP code.

tomda

3:13 pm on Nov 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Fotiman, sorry for that, my bad. That was not clever, indeed.
But cleaning the code helped a lot since I forgot the error, a span with onclick element wasn't close !

Thanks for your time and sorry for this useless thread...

Fotiman

4:10 pm on Nov 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Glad you got it sorted. Often just looking at the generated code can lead to finding some little thing that was missed. :)