How to pass PHP value to Javascript and redirect to other page? -
why cant pass value php code onclick function on button javascript function depcheck2()? redirect 2 different pages depending on value carries. please me?
<html> <head> <?php $company_id = $_get['cont']; $query = "select count(department_id) countdep department company_id=$company_id"; $result = mysql_query($query, $db) or die(mysql_error($db)); $row = mysql_fetch_array($result); extract($row); ?> <script> function depcheck2(x){ var countrow = '<?php echo "$countdep";?>'; if (countrow>0){ window.location.assign("editevent.php?id="+x""); } else{ window.location.assign("editevent.php2?id="+x""); } } </script> </head> <body> <?php include("config.php"); $company_id = $_get['cont']; $query = "select * event_details company_id=".$company_id." order eventdetails_id desc"; $result=mysql_query($query, $db) or die(mysql_error($db)); echo "<table border=1 width='1000'>"; echo "<tr><th>serial number</th><th>status</th><th>event type</th><th>date of event</th><th>end date</th><th>details</th></tr>"; while ($row = mysql_fetch_array($result)) { extract($row); echo " <tr> <td align='center'>$eventdetails_id</td> <td align='center'>$status</td> <td align='center'>$eventtype</td> <td align='center'>$startdate</td> <td align='center'>$enddate</td> <td align='center'> <input type='button' value='details' class='btn btn-large btn-primary' onclick='depcheck2(\''.$eventdetails_id.'\')'> </td> </tr> "; } ?> </table> </body> </html>
at first: <?php echo "$countdep";?>
contains $countdep
not defined in php.
it present in db query haven't assigned variable $result
then window.location.assign("editevent.php?id="+x"");
syntax wrong.
you have quotes @ end.
it should window.location.assign("editevent.php?id="+x);
Comments
Post a Comment