ag3nt42 Posted May 21, 2008 Share Posted May 21, 2008 I'm building a calendar and I have the php building the calendar interface on the fly... I'm trying to figure out how I can change a variable value through an Onclick event or the like. any ideas would be appreciated.. thankx everyone. so say i have <?php $z=0; ?> <a href='#'onclick='<?php echo($z++); ?>'>NEXT MONTH</a> upon click the link the month will change because the variable value has changed. only thing is i can't get it to work. anyone know of a better way to do this? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted May 21, 2008 Share Posted May 21, 2008 You can't do that via PHP, unless the page reloads you then must use JavaScript. Quote Link to comment Share on other sites More sharing options...
chronister Posted May 21, 2008 Share Posted May 21, 2008 <?php $z=0; ?> <a href="/destination_page.php?month=<?php echo $z++; ?>">NEXT MONTH</a> Then in your code you would use <?php $month = $_GET['month']; ?> Nate Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted May 21, 2008 Author Share Posted May 21, 2008 it almost works.. but i think the problem is that each time you refresh the page z gets the 0 value again.. so it just stays 0 all the time Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted May 21, 2008 Author Share Posted May 21, 2008 i have tried using javascript to change the value of z but z is also used thorughout a bunch of php functions and loops that i have in place to dynamically build this thing... it doesn't seem to want to let me change the value of a php variable using js Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted May 21, 2008 Share Posted May 21, 2008 You can not change an onclick value, at least I don't know how, so I do a work around. First I remove it, then I add it. // I use remove and set attribute tagname.removeAttribute('onclick'); // attribute name tagname.setAttribute('onclick',(z+1)) // attribute name followed by its value Quote Link to comment Share on other sites More sharing options...
chronister Posted May 21, 2008 Share Posted May 21, 2008 JS is client side and php is server side.... JS CANNOT affect PHP values unless you use AJAX requests. Post your actual code here so we can see it. You won't want to set your value statically every time. You will look to the url and see if a value has been passed. e.g. <?php if(!isset($_GET['month'])) { $z = 0; } else { $z = $_GET['month']; } ?> If month was passed through the url, then this would use that as the value of z, if not then $z is set statically. Nate Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted May 21, 2008 Author Share Posted May 21, 2008 ok well i didn't want to do this but if it will help figure this out <?php //LIBRARY VARIABLES $month = $_GET['month']; $z=0; $mL= array('January','February','March','April','May','June','July','August','September','October','November','December'); $m=$mL[$z]; $dL= array('31','29','31','30','31','30','31','31','30','31','30','31'); $d=$dL[$z]; $dn= array('Sunday','Monday','Tuesday','Wensday','Thursday','Friday','Saturday'); $y= '2008'; $x=0; echo ('There are ' . $d .' days in ' . $m . ' ' . $y); ?> <!-- MONTH/DAYs SWITCHER HTML //--> <br /><br /><a href='schedule.php?month=<?php echo $z++; ?>'>NEXT MONTH >></a> <!-- HTML //--> <table id='dayTable'> <tr> <!-- END HTML //--> <?php // LIST OUR DAYS NAMES while($x<=6) { echo("<td>" . $dn[$x] . "</td>"); $x++; } ?> <!-- HTML //--> </tr> <tr> <!-- END HTML //--> <?php // THE VARIABLES $i=0; $n=""; $MakeDayB= "<td><div id='Daybox'>"; $MakeDayE= "</div></td>"; // START THE LOOP TO BUILD THE CALENDAR while($i<=34) { echo $MakeDayB . $n . $MakeDayE; $i++; // START MONTH SPECIFIC CHECKS //JAN if($i>=2&&$y=="2008"&&$m==$mL[0]) { $n++; } if($i>=$dL[0]+2&&$m==$mL[0]) { $n=""; } //FEB if($i>=5&&$y=="2008"&&$m==$mL[1]) { $n++; } if($i>=$dL[1]+5&&$m==$mL[1]) { $n=""; } //MAR //BREAK THE CALENDAR DOWN EVERY 7 DAYS if ($i==7||$i==14||$i==21||$i==28) { echo("</tr><tr>"); } else { echo(""); } } ?> <!-- HTML //--> </tr> </table> Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted May 21, 2008 Author Share Posted May 21, 2008 JS is client side and php is server side.... JS CANNOT affect PHP values unless you use AJAX requests. Post your actual code here so we can see it. You won't want to set your value statically every time. You will look to the url and see if a value has been passed. e.g. <?php if(!isset($_GET['month'])) { $z = 0; } else { $z = $_GET['month']; } ?> If month was passed through the url, then this would use that as the value of z, if not then $z is set statically. Nate I tried this but it doesn't seem to want to change the value of z Quote Link to comment Share on other sites More sharing options...
jonsjava Posted May 21, 2008 Share Posted May 21, 2008 <?php //LIBRARY VARIABLES if (!(isset($_GET['month']))){ $z=0; } else{ $z = $_GET['month']; } $mL= array('January','February','March','April','May','June','July','August','September','October','November','December'); $m=$mL[$z]; $dL= array('31','29','31','30','31','30','31','31','30','31','30','31'); $d=$dL[$z]; $dn= array('Sunday','Monday','Tuesday','Wensday','Thursday','Friday','Saturday'); $y= '2008'; $x=0; echo ('There are ' . $d .' days in ' . $m . ' ' . $y); ?> <!-- MONTH/DAYs SWITCHER HTML //--> <br /><br /><a href='?month=<?php echo $z + 1; ?>'>NEXT MONTH >></a> <!-- HTML //--> <table id='dayTable'> <tr> <!-- END HTML //--> <?php // LIST OUR DAYS NAMES while($x<=6) { echo("<td>" . $dn[$x] . "</td>"); $x++; } ?> <!-- HTML //--> </tr> <tr> <!-- END HTML //--> <?php // THE VARIABLES $i=0; $n=""; $MakeDayB= "<td><div id='Daybox'>"; $MakeDayE= "</div></td>"; // START THE LOOP TO BUILD THE CALENDAR while($i<=34) { echo $MakeDayB . $n . $MakeDayE; $i++; // START MONTH SPECIFIC CHECKS //JAN if($i>=2&&$y=="2008"&&$m==$mL[0]) { $n++; } if($i>=$dL[0]+2&&$m==$mL[0]) { $n=""; } //FEB if($i>=5&&$y=="2008"&&$m==$mL[1]) { $n++; } if($i>=$dL[1]+5&&$m==$mL[1]) { $n=""; } //MAR //BREAK THE CALENDAR DOWN EVERY 7 DAYS if ($i==7||$i==14||$i==21||$i==28) { echo("</tr><tr>"); } else { echo(""); } } ?> <!-- HTML //--> </tr> </table> Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted May 21, 2008 Author Share Posted May 21, 2008 beautiful man.. u rock... thanx problem solved Quote Link to comment Share on other sites More sharing options...
jonsjava Posted May 21, 2008 Share Posted May 21, 2008 Glad to help! Could you please click on the "Solved" Button? Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted May 21, 2008 Author Share Posted May 21, 2008 i was looking for a solved button i didn't think you guys had one here ... which button? heh heh found it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.