Jump to content

PHP and Javascript


thomasw_lrd

Recommended Posts

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
Share on other sites

<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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.