Reputation: 99
Could anybody help me with this little issue. Im trying to change the class of a page number if clicked. but im trying through a js function call using a dynamic php ID . The code below should show you what i mean, Basically the function would change the class of the selected number.
echo"
<div class='pagebuttonsdiv'>";
for ( $x =0 ; $x < $pagesnum ; $x++ ) {
$pagex=$x+1;
if ($pagex<1) {$pagex==1;}
if ($pagex>$pagesnum) {$pagex==$pagesnum;};
if ($x > $pagesnum) {$x==$pagesnum;}
echo "
<div id='{$x}' class='pagebuttons' onclick='pageclick({$x},
{$display}, {$maxresults} , {$startfrom});'>
{$pagex}</div>";
if ($x==$ifclicked) {?>
<script type="text/javascript">
document.getElementById({$x}).className =
'pagebuttonsclicked';}
</script>
<?php
};
};
echo"
</div>
";
Anybody have any idea how i should go about this, Many thanks in advance.
Upvotes: 2
Views: 434
Reputation: 99
Simple Answer -
echo"
";
for ( $x =0 ; $x < $pagesnum ; $x++ ) {
$pagex=$x+1;
if ($pagex<1) {$pagex==1;}
if ($pagex>$pagesnum) {$pagex==$pagesnum;};
if ($x > $pagesnum) {$x==$pagesnum;}
echo "
<div id='{$x}' class='pagebuttons' onclick='pageclick({$x},{$display}, {$maxresults} , {$startfrom});'>
{$pagex}</div>";
if ($x==$ifclicked) { echo " <script> document.getElementById({$x}).className='pagebuttonsclicked' </script> ";};
};
echo"
</div>
<br>
";
call the function from php to change class. = onlclicking the number, it changes its class to change whatever you wish it to change according to the new css class... I changed the border surround color...
Upvotes: 0
Reputation: 61
<div id="id[<?php echo $x; ?>]" class="pagebuttons" onclick="pageclick(<?php echo$x; ?>)">
{$pagex}</div>
Not sure why are you sending all those variables in function. you just need the id to change that.
Upvotes: 1