thomasw_lrd Posted August 31, 2011 Share Posted August 31, 2011 I need some help. I'm having trouble calling a javascript function from a php script <?php include ('security.inc'); include ('head.inc'); echo ' <table class="menutable"> <tr> <td nowrap> <div id="sidemenu" style="display:block;"> <ul id="navbar">'; // database-driven menu groups // get the menu items and groups that this user has access to if (!isset($_SESSION['usergroupsin']) || $_SESSION['usergroupsin']==''){ $menurs=array(); } else { $sql="SELECT mg_name, mg_desc, mi_name, mi_desc, mi_link, mi_external_link, mgg_gr_id, mig_gr_id FROM tbl_menu_items INNER JOIN tbl_menu_groups ON mi_mg_id=mg_id AND mg_active='y' LEFT JOIN tbl_menu_groups_groups ON mgg_mg_id=mg_id AND mgg_active='y' LEFT JOIN tbl_menu_items_groups ON mig_mi_id=mi_id AND mig_active='y' WHERE ( mgg_gr_id IN (".$_SESSION['usergroupsin'].") OR mig_gr_id IN (".$_SESSION['usergroupsin'].") OR mi_secure='n' ) AND mi_active='y' AND mg_left_menu='y' GROUP BY mg_name, mg_desc, mi_name, mi_desc, mi_link, mi_external_link ORDER BY mg_sort, mi_sort"; $menurs=myload($sql); } $last_mg_name=''; if (count($menurs)>0){ foreach ($menurs as $m){ // show the group heading if we haven't already shown it if ($m['mg_name']<>$last_mg_name){ echo '<li><strong> <br>'.$m['mg_name'].'</strong></li>'; $last_mg_name=$m['mg_name']; } // determine whether this is a system link or not if ($m['mi_external_link']=='y'){ $thisurl=$m['mi_link']; } else { $thisurl=$config['system_url_root'].$m['mi_link']; } echo '<li><a title="'.$m['mi_desc'].'" href="'.$thisurl.'"><strong> - '.$m ['mi_name'].'</strong></a></li>'; } } echo ' </ul> </div> </td> [b]<input class="button" type="button" value="Hide Menu" onclick="setTable('sidemenu');return true">[/b] <td width="100%"> <div id="mainwindow"> <!-- BEGIN PAGE CONTENT --> '; ?> My javacscipt function is in the head.inc. I can post that if needed. The bolded part is what I'm having trouble with. Specifically, the onclick. Without that, my script works, if I have the onclick in there, I get a blank page. I'm trying to hide/show the div=sidemenu. If anybody has any suggestions, I'm open to it. Link to comment https://forums.phpfreaks.com/topic/246134-php-and-javascript/ Share on other sites More sharing options...
cssfreakie Posted August 31, 2011 Share Posted August 31, 2011 <input class="button" type="button" value="Hide Menu" onclick="setTable('sidemenu');return true"> you can't do that, your using single quotes around the string you echo. If you use them inside that string, you need to escape the single quotes. Like so: echo 'lalalala this is a string isn\'t it?'; So your code should be: onclick="setTable(\'sidemenu\');return true"> Link to comment https://forums.phpfreaks.com/topic/246134-php-and-javascript/#findComment-1264060 Share on other sites More sharing options...
thomasw_lrd Posted September 1, 2011 Author Share Posted September 1, 2011 I really hope that works can't test till I get to work but thank you very much. I tried escaping just about everything else but those quotes Link to comment https://forums.phpfreaks.com/topic/246134-php-and-javascript/#findComment-1264119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.