Javascript en PHP combineren..
Ik zit met het volgende probleem.. Ik ben bezig een menu te maken dat opgebouwt wordt uit javascript icm een DB.
Nu werkt mijn menu prima als ik het gewoon op de volgende manier doe..
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?
/***
This is the menu creation code - place it right after you body tag
Feel free to add this to a stand-alone js file and link it to your page.
**/
function findPos(){
x=0; y=0; var el,temp
el = document.getElementById("divMenu");
if(el.offsetParent){
temp = el
while(temp.offsetParent){ //Looping parent elements to get the offset of them as well
temp=temp.offsetParent;
x+=temp.offsetLeft
y+=temp.offsetTop;
}
}
x+=el.offsetLeft
y+=el.offsetTop
return [x,y]
}
pos = findPos();
//Menu object creation
oCMenu=new makeCM("oCMenu") //Making the menu object. Argument: menuname
oCMenu.frames = 0
oCMenu.fromLeft=(pos[0])
oCMenu.fromTop=(pos[1])
//We also need to "re place" the menu on resize. So:
oCMenu.onresize="pos = findPos(); oCMenu.fromLeft=pos[0]; oCMenu.fromTop=(pos[1])"
//Menu properties
oCMenu.pxBetween=0
oCMenu.rows=1
oCMenu.menuPlacement="left"
oCMenu.offlineRoot=""
oCMenu.onlineRoot=""
oCMenu.resizeCheck=1
oCMenu.wait=1000
oCMenu.fillImg="cm_fill.gif"
oCMenu.zIndex=0
//Background bar properties
oCMenu.useBar=1
oCMenu.barWidth=""
oCMenu.barHeight="menu"
oCMenu.barClass="clBar"
oCMenu.barX=0
oCMenu.barY=0
oCMenu.barBorderX=0
oCMenu.barBorderY=0
oCMenu.barBorderClass=""
//Level properties - ALL properties have to be spesified in level 0
oCMenu.level[0]=new cm_makeLevel() //Add this for each new level
oCMenu.level[0].width=155
oCMenu.level[0].height=50
oCMenu.level[0].regClass="clLevel0"
oCMenu.level[0].overClass="clLevel0over"
oCMenu.level[0].borderX=0
oCMenu.level[0].borderY=0
oCMenu.level[0].borderClass="clLevel0border"
oCMenu.level[0].offsetX=0
oCMenu.level[0].offsetY=0
oCMenu.level[0].rows=0
oCMenu.level[0].arrow=0
oCMenu.level[0].arrowWidth=0
oCMenu.level[0].arrowHeight=0
oCMenu.level[0].align="bottom"
//EXAMPLE SUB LEVEL[1] PROPERTIES - You have to specify the properties you want different from LEVEL[0] - If you want all items to look the same just remove this
oCMenu.level[1]=new cm_makeLevel() //Add this for each new level (adding one to the number)
oCMenu.level[1].width=oCMenu.level[0].width+100
oCMenu.level[1].height=25
oCMenu.level[1].regClass="clLevel1"
oCMenu.level[1].overClass="clLevel1over"
oCMenu.level[1].borderX=0
oCMenu.level[1].borderY=1
oCMenu.level[1].align="right"
oCMenu.level[1].offsetX=-(oCMenu.level[0].width-2)/2+20
oCMenu.level[1].offsetY=0
oCMenu.level[1].borderClass="clLevel1border"
//EXAMPLE SUB LEVEL[2] PROPERTIES - You have to spesify the properties you want different from LEVEL[1] OR LEVEL[0] - If you want all items to look the same just remove this
oCMenu.level[2]=new cm_makeLevel() //Add this for each new level (adding one to the number)
oCMenu.level[2].width=150
oCMenu.level[2].height=20
oCMenu.level[2].offsetX=0
oCMenu.level[2].offsetY=0
oCMenu.level[2].regClass="clLevel2"
oCMenu.level[2].overClass="clLevel2over"
oCMenu.level[2].borderClass="clLevel2border"
/******************************************
Menu item creation:
myCoolMenu.makeMenu(name, parent_name, text, link, target, width, height, regImage, overImage, regClass, overClass , align, rows, nolink, onclick, onmouseover, onmouseout)
*************************************/
oCMenu.makeMenu('page1','','opleidingen','', '', '', '', 'afb/menu_1.gif', 'afb/menu_1_over.gif')
oCMenu.makeMenu( 'page1_4', 'page1', 'WO Opleidingen', '/vervolg.php?pagina_id=4', '', '')
oCMenu.makeMenu( 'page1_5', 'page1', 'HBO Opleidingen', '/vervolg.php?pagina_id=5', '', '')
oCMenu.makeMenu( 'page1_3', 'page1', '(V)MBO Opleidingen', '/vervolg.php?pagina_id=3', '', '')
oCMenu.makeMenu('page2','','Facts en Figures','', '', '', '', 'afb/menu_2.gif', 'afb/menu_2_over.gif')
oCMenu.makeMenu( 'page2_9', 'page2', 'Facts & Figures', '/vervolg.php?pagina_id=9', '', '')
oCMenu.makeMenu( 'page2_7', 'page2', '(V)MBO Opleidingen', '/vervolg.php?pagina_id=7', '', '')
oCMenu.makeMenu('page3','','Trainingen','', '', '', '', 'afb/menu_3.gif', 'afb/menu_3_over.gif')
oCMenu.makeMenu('page4','','Fun','', '', '', '', 'afb/menu_4.gif', 'afb/menu_4_over.gif')
oCMenu.makeMenu('page5','','Vacatures','', '', '', '', 'afb/menu_5.gif', 'afb/menu_5_over.gif')
oCMenu.construct()
?>
/***
This is the menu creation code - place it right after you body tag
Feel free to add this to a stand-alone js file and link it to your page.
**/
function findPos(){
x=0; y=0; var el,temp
el = document.getElementById("divMenu");
if(el.offsetParent){
temp = el
while(temp.offsetParent){ //Looping parent elements to get the offset of them as well
temp=temp.offsetParent;
x+=temp.offsetLeft
y+=temp.offsetTop;
}
}
x+=el.offsetLeft
y+=el.offsetTop
return [x,y]
}
pos = findPos();
//Menu object creation
oCMenu=new makeCM("oCMenu") //Making the menu object. Argument: menuname
oCMenu.frames = 0
oCMenu.fromLeft=(pos[0])
oCMenu.fromTop=(pos[1])
//We also need to "re place" the menu on resize. So:
oCMenu.onresize="pos = findPos(); oCMenu.fromLeft=pos[0]; oCMenu.fromTop=(pos[1])"
//Menu properties
oCMenu.pxBetween=0
oCMenu.rows=1
oCMenu.menuPlacement="left"
oCMenu.offlineRoot=""
oCMenu.onlineRoot=""
oCMenu.resizeCheck=1
oCMenu.wait=1000
oCMenu.fillImg="cm_fill.gif"
oCMenu.zIndex=0
//Background bar properties
oCMenu.useBar=1
oCMenu.barWidth=""
oCMenu.barHeight="menu"
oCMenu.barClass="clBar"
oCMenu.barX=0
oCMenu.barY=0
oCMenu.barBorderX=0
oCMenu.barBorderY=0
oCMenu.barBorderClass=""
//Level properties - ALL properties have to be spesified in level 0
oCMenu.level[0]=new cm_makeLevel() //Add this for each new level
oCMenu.level[0].width=155
oCMenu.level[0].height=50
oCMenu.level[0].regClass="clLevel0"
oCMenu.level[0].overClass="clLevel0over"
oCMenu.level[0].borderX=0
oCMenu.level[0].borderY=0
oCMenu.level[0].borderClass="clLevel0border"
oCMenu.level[0].offsetX=0
oCMenu.level[0].offsetY=0
oCMenu.level[0].rows=0
oCMenu.level[0].arrow=0
oCMenu.level[0].arrowWidth=0
oCMenu.level[0].arrowHeight=0
oCMenu.level[0].align="bottom"
//EXAMPLE SUB LEVEL[1] PROPERTIES - You have to specify the properties you want different from LEVEL[0] - If you want all items to look the same just remove this
oCMenu.level[1]=new cm_makeLevel() //Add this for each new level (adding one to the number)
oCMenu.level[1].width=oCMenu.level[0].width+100
oCMenu.level[1].height=25
oCMenu.level[1].regClass="clLevel1"
oCMenu.level[1].overClass="clLevel1over"
oCMenu.level[1].borderX=0
oCMenu.level[1].borderY=1
oCMenu.level[1].align="right"
oCMenu.level[1].offsetX=-(oCMenu.level[0].width-2)/2+20
oCMenu.level[1].offsetY=0
oCMenu.level[1].borderClass="clLevel1border"
//EXAMPLE SUB LEVEL[2] PROPERTIES - You have to spesify the properties you want different from LEVEL[1] OR LEVEL[0] - If you want all items to look the same just remove this
oCMenu.level[2]=new cm_makeLevel() //Add this for each new level (adding one to the number)
oCMenu.level[2].width=150
oCMenu.level[2].height=20
oCMenu.level[2].offsetX=0
oCMenu.level[2].offsetY=0
oCMenu.level[2].regClass="clLevel2"
oCMenu.level[2].overClass="clLevel2over"
oCMenu.level[2].borderClass="clLevel2border"
/******************************************
Menu item creation:
myCoolMenu.makeMenu(name, parent_name, text, link, target, width, height, regImage, overImage, regClass, overClass , align, rows, nolink, onclick, onmouseover, onmouseout)
*************************************/
oCMenu.makeMenu('page1','','opleidingen','', '', '', '', 'afb/menu_1.gif', 'afb/menu_1_over.gif')
oCMenu.makeMenu( 'page1_4', 'page1', 'WO Opleidingen', '/vervolg.php?pagina_id=4', '', '')
oCMenu.makeMenu( 'page1_5', 'page1', 'HBO Opleidingen', '/vervolg.php?pagina_id=5', '', '')
oCMenu.makeMenu( 'page1_3', 'page1', '(V)MBO Opleidingen', '/vervolg.php?pagina_id=3', '', '')
oCMenu.makeMenu('page2','','Facts en Figures','', '', '', '', 'afb/menu_2.gif', 'afb/menu_2_over.gif')
oCMenu.makeMenu( 'page2_9', 'page2', 'Facts & Figures', '/vervolg.php?pagina_id=9', '', '')
oCMenu.makeMenu( 'page2_7', 'page2', '(V)MBO Opleidingen', '/vervolg.php?pagina_id=7', '', '')
oCMenu.makeMenu('page3','','Trainingen','', '', '', '', 'afb/menu_3.gif', 'afb/menu_3_over.gif')
oCMenu.makeMenu('page4','','Fun','', '', '', '', 'afb/menu_4.gif', 'afb/menu_4_over.gif')
oCMenu.makeMenu('page5','','Vacatures','', '', '', '', 'afb/menu_5.gif', 'afb/menu_5_over.gif')
oCMenu.construct()
?>
(dit is zonder php maar dat laatste stukje heb ik letterlijk gecopierd van wat mijn volgende script maakt..
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?
echo"<br><br>";
$sql = "SELECT * FROM tbl_catagorie WHERE menuitem = 1 ORDER BY catagorie_id";
$res = mysql_query($sql);
while ($rij = mysql_fetch_object($res))
{
echo"oCMenu.makeMenu('page".$rij->catagorie_id."','','".$rij->naam."','', '', '', '', '".$rij->afbeelding."', '".$rij->afbeelding_over."') ";
echo"<br>";
$sql2 = "SELECT * FROM tbl_pagina WHERE catagorie_id = ".$rij->catagorie_id." && menuitem != 0";
$res2 = mysql_query($sql2);
while ($rij2 = mysql_fetch_object($res2))
{
echo"oCMenu.makeMenu(
'page".$rij2->catagorie_id."_".$rij2->pagina_id."', 'page".$rij2->catagorie_id."', '".$rij2->titel."', '/vervolg.php?pagina_id=".$rij2->pagina_id."', '', '') ";
echo"<BR>";
}
echo"<BR>";
}
echo" oCMenu.construct() ";
?>
echo"<br><br>";
$sql = "SELECT * FROM tbl_catagorie WHERE menuitem = 1 ORDER BY catagorie_id";
$res = mysql_query($sql);
while ($rij = mysql_fetch_object($res))
{
echo"oCMenu.makeMenu('page".$rij->catagorie_id."','','".$rij->naam."','', '', '', '', '".$rij->afbeelding."', '".$rij->afbeelding_over."') ";
echo"<br>";
$sql2 = "SELECT * FROM tbl_pagina WHERE catagorie_id = ".$rij->catagorie_id." && menuitem != 0";
$res2 = mysql_query($sql2);
while ($rij2 = mysql_fetch_object($res2))
{
echo"oCMenu.makeMenu(
'page".$rij2->catagorie_id."_".$rij2->pagina_id."', 'page".$rij2->catagorie_id."', '".$rij2->titel."', '/vervolg.php?pagina_id=".$rij2->pagina_id."', '', '') ";
echo"<BR>";
}
echo"<BR>";
}
echo" oCMenu.construct() ";
?>
ALs ik dit echter toevoeg gewoon zoals het in het 2e voorbeeld staat doet hij het niet...
Hoe komt dit?
WIe kan mij helpen..??
GRoeten Marijn
Zie ook even de error-console (onder 'extra's' in het menu in Firefox), geeft die ook een foutmelding?
Dus ook <br>'s die moeten dus weg..
Gewijzigd op 01/01/1970 01:00:00 door Marijn
'page".$rij2->catagorie_id."_".$rij2->pagina_id."', 'page".$rij2->catagorie_id."', '".$rij2->titel."', '/vervolg.php?pagina_id=".$rij2->pagina_id."', '', '')</script> ";
echo"<BR>";
}
echo"<BR>";
}
echo"<script language="text/javascript">oCMenu.construct()</script> ";
alles staat idd tussen script tags... volgende keer op letten ;). Javascript kun je niet uitvoeren in PHP hierdoor moet je eerst de <script...>....</script> tags toevoegen.
Gewijzigd op 01/01/1970 01:00:00 door Jurgen assaasas
en dat moet je dan includen of is er een andere manier?
je hoeft niks te includen als jou functies correct zijn zou het zo moeten werken. Je moet er enkel op letten dat je, je javascript binnen de <script> tags houdt dit kun je wel door bijv: echo "<script>functie()</script>";
maar ook geen foutmeldingen..
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?
$sql = "SELECT * FROM tbl_catagorie WHERE menuitem = 1 ORDER BY catagorie_id";
$res = mysql_query($sql);
while ($rij = mysql_fetch_object($res))
{
echo"<script language=\"text/javascript\">oCMenu.makeMenu(
'page".$rij->catagorie_id."','','".$rij->naam."','', '', '', '', '".$rij->afbeelding."', '".$rij->afbeelding_over."')</script> ";
echo"<BR>";
}
echo"<script language=\"text/javascript\">oCMenu.construct()</script> ";
?>
$sql = "SELECT * FROM tbl_catagorie WHERE menuitem = 1 ORDER BY catagorie_id";
$res = mysql_query($sql);
while ($rij = mysql_fetch_object($res))
{
echo"<script language=\"text/javascript\">oCMenu.makeMenu(
'page".$rij->catagorie_id."','','".$rij->naam."','', '', '', '', '".$rij->afbeelding."', '".$rij->afbeelding_over."')</script> ";
echo"<BR>";
}
echo"<script language=\"text/javascript\">oCMenu.construct()</script> ";
?>
Dat geeft in de bron dit
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
<?
<script language="text/javascript">oCMenu.makeMenu(
'page1','','opleidingen','', '', '', '', 'afb/menu_1.gif', 'afb/menu_1_over.gif')</script> <BR><script language="text/javascript">oCMenu.makeMenu(
'page2','','Facts en Figures','', '', '', '', 'afb/menu_2.gif', 'afb/menu_2_over.gif')</script> <BR><script language="text/javascript">oCMenu.makeMenu(
'page3','','Trainingen','', '', '', '', 'afb/menu_3.gif', 'afb/menu_3_over.gif')</script> <BR><script language="text/javascript">oCMenu.makeMenu(
'page4','','Fun','', '', '', '', 'afb/menu_4.gif', 'afb/menu_4_over.gif')</script> <BR><script language="text/javascript">oCMenu.makeMenu(
'page5','','Vacatures','', '', '', '', 'afb/menu_5.gif', 'afb/menu_5_over.gif')</script> <BR><script language="text/javascript">oCMenu.construct()</script>
?>
<script language="text/javascript">oCMenu.makeMenu(
'page1','','opleidingen','', '', '', '', 'afb/menu_1.gif', 'afb/menu_1_over.gif')</script> <BR><script language="text/javascript">oCMenu.makeMenu(
'page2','','Facts en Figures','', '', '', '', 'afb/menu_2.gif', 'afb/menu_2_over.gif')</script> <BR><script language="text/javascript">oCMenu.makeMenu(
'page3','','Trainingen','', '', '', '', 'afb/menu_3.gif', 'afb/menu_3_over.gif')</script> <BR><script language="text/javascript">oCMenu.makeMenu(
'page4','','Fun','', '', '', '', 'afb/menu_4.gif', 'afb/menu_4_over.gif')</script> <BR><script language="text/javascript">oCMenu.makeMenu(
'page5','','Vacatures','', '', '', '', 'afb/menu_5.gif', 'afb/menu_5_over.gif')</script> <BR><script language="text/javascript">oCMenu.construct()</script>
?>
terwijl hij dit:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?
oCMenu.makeMenu('page1','','opleidingen','', '', '', '', 'afb/menu_1.gif', 'afb/menu_1_over.gif')
oCMenu.makeMenu( 'page1_4', 'page1', 'WO Opleidingen', '/vervolg.php?pagina_id=4', '', '')
oCMenu.makeMenu( 'page1_5', 'page1', 'HBO Opleidingen', '/vervolg.php?pagina_id=5', '', '')
oCMenu.makeMenu( 'page1_3', 'page1', '(V)MBO Opleidingen', '/vervolg.php?pagina_id=3', '', '')
oCMenu.makeMenu('page2','','Facts en Figures','', '', '', '', 'afb/menu_2.gif', 'afb/menu_2_over.gif')
oCMenu.makeMenu( 'page2_9', 'page2', 'Facts & Figures', '/vervolg.php?pagina_id=9', '', '')
oCMenu.makeMenu( 'page2_7', 'page2', '(V)MBO Opleidingen', '/vervolg.php?pagina_id=7', '', '')
oCMenu.makeMenu('page3','','Trainingen','', '', '', '', 'afb/menu_3.gif', 'afb/menu_3_over.gif')
oCMenu.makeMenu('page4','','Fun','', '', '', '', 'afb/menu_4.gif', 'afb/menu_4_over.gif')
oCMenu.makeMenu('page5','','Vacatures','', '', '', '', 'afb/menu_5.gif', 'afb/menu_5_over.gif')
oCMenu.construct()
?>
oCMenu.makeMenu('page1','','opleidingen','', '', '', '', 'afb/menu_1.gif', 'afb/menu_1_over.gif')
oCMenu.makeMenu( 'page1_4', 'page1', 'WO Opleidingen', '/vervolg.php?pagina_id=4', '', '')
oCMenu.makeMenu( 'page1_5', 'page1', 'HBO Opleidingen', '/vervolg.php?pagina_id=5', '', '')
oCMenu.makeMenu( 'page1_3', 'page1', '(V)MBO Opleidingen', '/vervolg.php?pagina_id=3', '', '')
oCMenu.makeMenu('page2','','Facts en Figures','', '', '', '', 'afb/menu_2.gif', 'afb/menu_2_over.gif')
oCMenu.makeMenu( 'page2_9', 'page2', 'Facts & Figures', '/vervolg.php?pagina_id=9', '', '')
oCMenu.makeMenu( 'page2_7', 'page2', '(V)MBO Opleidingen', '/vervolg.php?pagina_id=7', '', '')
oCMenu.makeMenu('page3','','Trainingen','', '', '', '', 'afb/menu_3.gif', 'afb/menu_3_over.gif')
oCMenu.makeMenu('page4','','Fun','', '', '', '', 'afb/menu_4.gif', 'afb/menu_4_over.gif')
oCMenu.makeMenu('page5','','Vacatures','', '', '', '', 'afb/menu_5.gif', 'afb/menu_5_over.gif')
oCMenu.construct()
?>
zou moeten weegeven
Gewijzigd op 01/01/1970 01:00:00 door Marijn
niemand?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?
$sql = "SELECT * FROM tbl_catagorie WHERE menuitem = 1 ORDER BY catagorie_id";
$res = mysql_query($sql);
echo '<script language="text/javascript">';
while ($rij = mysql_fetch_object($res))
{
echo "oCMenu.makeMenu(
'page".$rij->catagorie_id."','','".$rij->naam."','', '', '', '', '".$rij->afbeelding."', '".$rij->afbeelding_over."');\n";
}
echo '</script>';
echo"<script language=\"text/javascript\">oCMenu.construct()</script> ";
?>
$sql = "SELECT * FROM tbl_catagorie WHERE menuitem = 1 ORDER BY catagorie_id";
$res = mysql_query($sql);
echo '<script language="text/javascript">';
while ($rij = mysql_fetch_object($res))
{
echo "oCMenu.makeMenu(
'page".$rij->catagorie_id."','','".$rij->naam."','', '', '', '', '".$rij->afbeelding."', '".$rij->afbeelding_over."');\n";
}
echo '</script>';
echo"<script language=\"text/javascript\">oCMenu.construct()</script> ";
?>