Jump to content

using javascript in php


demonforce

Recommended Posts

hi :)

 

i have a small, but irritating problem.

 

i have a database with all kind of news in it, and i want it to show the newwest 3 id's in a collapse menu.

 

i allready have the collapse script, and the php part, but cause some reason it wont work.

 

code:

 

COLLAPSE

<script type="text/javascript">
function switchMenu(obj) {
var el = document.getElementById(obj);
if ( el.style.display != "none" ) {
	el.style.display = 'none';
}
else {
	el.style.display = '';
}
}
</script>

 

STYLE

<style type="text/css">
<!--
body {
text-align:center;
margin:30px;
}
#wrapper {
text-align:left;
margin:0 auto;
width:150px;
min-height:10px;
border:1px solid #ccc;
padding:10px;
}
a {
color:blue;
cursor:pointer;
}
#id1 {
border:1px solid #ccc;
background:#f2f2f2;
padding:20px;
}
-->
</style>

 

 

PHP

     <?php

require("mysql.connect.php");

$query = @mysql_query("SELECT * FROM nieuws") or die(mysql_error());

	while($values = mysql_fetch_array($query))
	{ 

		$id = $values['id'];
		$naam = $values['naam'];
		$bericht = $values['bericht'];

echo "<div id='wrapper'>";
echo "<a onclick='switchMenu('id1');' title='naam'>naam</a>";
echo "<div id='id1'>bericht</div>";
echo "</div>";

	}
	?>

 

 

what do i do wrong?

Link to comment
https://forums.phpfreaks.com/topic/67827-using-javascript-in-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.