Page 1 of 1
Again syntax problems...
Posted: Thu Jul 22, 2010 3:30 am
by jotae
Code: Select all
<?php
echo "<div id='menu'><dl><dt onmouseover='javascript:mostrar();'><a href='index.php'>Home</a></dt></dl>\n";
echo "<dl><dt onmouseover='javascript:mostrar();'><a href='catalogo.php'>Catálogo</a></dt></dl>\n";
echo "<dl><dt onmouseover='javascript:mostrar();'><a href='buscar.php'>Buscar</a></dt></dl>\n";
echo "<dl><dt onmouseover='javascript:mostrar();'><a href='tutor.php'>Su 1er Midi</a></dt></dl>\n";
echo "<dl><dt onmouseover='javascript:mostrar('smenu1');'>Midi Tutor</dt>\n"; //THIS LINE PRODUCE A SYNTAX ERROR....
echo "<dd id='smenu1'>\n";
echo "<ul>\n";
echo "<li><a href='miditut.php'>Inicio</a></li>\n";
echo "<li><a href='midicos.php'>Midi Cosas</a></li>\n";
echo "<li><a href='midigm.php'>General Midi</a></li>\n";
echo "<li><a href='midique.php'>Qué Hacer</a></li>\n";
echo "<li><a href='midicom1.php'>Compu 1</a></li>\n";
echo "<li><a href='midicom2.php'>Compu 2</a></li>\n";
echo "</ul></dd></dl>\n";
echo "<dl><dt onmouseover='javascript:mostrar();'><a href='mailto:prolatin@cwpanama.net'>Contáctenos</a></dt></dl>\n
echo "<dl><dt onmouseover='javascript:mostrar();'><a href='http://www.prolatin.com'>Prolatin</a></dt></dl></div>";
?>
The menu work but submenu (smenu1) don't work. Can help me, please?
The original code is ...
javascript:mostrar .....
Thx.
Re: Again syntax problems...
Posted: Thu Jul 22, 2010 4:34 am
by oscardog
What error does it print on the screen?
Also you're using invalid HTML. You should be using doubles quotes(") not single quotes('). So when outputting your first line you use:
Code: Select all
echo "<div id='menu'><dl><dt onmouseover='javascript:mostrar();'><a href='index.php'>Home</a></dt></dl>\n";
It should be:
Code: Select all
echo "<div id=\"menu\"><dl><dt onmouseover='javascript:mostrar();'><a href=\"index.php\">Home</a></dt></dl>\n";
That probably isn't causing the syntax error but it's probably not helping either.
Re: Again syntax problems...
Posted: Thu Jul 22, 2010 6:42 am
by DaiLaughing
I'm not sure you should be using definition lists either as these don't seem to be definitions!
The dog called oscar said you should use escaped double quotes and he's right because this line is wrong because the single quotes are confusing you and the browser:
Code: Select all
echo "<dl><dt onmouseover='javascript:mostrar('smenu1');'>Midi Tutor</dt>\n"; //THIS LINE PRODUCE A SYNTAX ERROR....
To the browser this will look like:
[text]<dl><dt onmouseover='javascript:mostrar('smenu1');'>Midi Tutor</dt>[/text]
So the onmouseover attribute's value will be:
[text]javascript:mostrar([/text]
because it ends at the next single quote. The rest of what you intended to be in that value is now garbage as far as the browser is concerned. If you had used this:
Code: Select all
echo "<dl><dt onmouseover=\"javascript:mostrar('smenu1');\">Midi Tutor</dt>\n";
There would have been no problem.
Re: Again syntax problems...
Posted: Thu Jul 22, 2010 12:54 pm
by jotae
Definitively doesn't work neither with double quotation marks neither with simple quotation marks. The menu appears but when I am about running the submenu, the options disappear and it is blocked. This is the complete code (changing quotation)
Code: Select all
<?php
echo '<div id="menu"><dl><dt onmouseover="javascript:mostrar();"><a href="index.php">Home</a></dt></dl><br />';
echo '<dl><dt onmouseover="javascript:mostrar();"><a href="catalogo.php">Catálogo</a></dt></dl><br />';
echo '<dl><dt onmouseover="javascript:mostrar();"><a href="buscar.php">Buscar</a></dt></dl><br />';
echo '<dl><dt onmouseover="javascript:mostrar();"><a href="tutor.php">Su 1er Midi</a></dt></dl><br />';
echo '<dl><dt onmouseover="javascript:mostrar("smenu1");">Midi Tutor</dt><br />';
echo '<dd id="smenu1"><br /><ul><br />';
echo '<li><a href="miditut.php">Inicio</a></li><br />';
echo '<li><a href="midicos.php">Midi Cosas</a></li><br />';
echo '<li><a href="midigm.php">General Midi</a></li><br />';
echo '<li><a href="midique.php">Qué Hacer</a></li><br />';
echo '<li><a href="midicom1.php">Compu 1</a></li><br />';
echo '<li><a href="midicom2.php">Compu 2</a></li><br />';
echo '</ul></dd></dl><br />';
echo '<dl><dt onmouseover="javascript:mostrar();"><a href="mailto:prolatin@cwpanama.net">Contáctenos</a></dt></dl><br />';
echo '<dl><dt onmouseover="javascript:mostrar();"><a href="http://www.prolatin.com">Prolatin</a></dt></dl></div>';
?>
This is the function
function mostrar(id) {
var d = document.getElementById(id);
for (var i = 1; i<=10; i++) {
if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
}
if (d) {d.style.display='block';}
}
thx
Re: Again syntax problems...
Posted: Thu Jul 22, 2010 1:25 pm
by Jade
Code: Select all
function mostrar(id) {
var d = document.getElementById(id);
for (var i = 1; i<=10; i++) {
if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
}
if (d) {d.style.display='';} //sometimes if you use block it doesnt remove the display=none status
}
Re: Again syntax problems...
Posted: Thu Jul 22, 2010 1:53 pm
by jotae
I think the function don't have problem because this is the original code in HTML and work perfectly:
<div id="menu">
<dl>
<dt onmouseover="javascript:mostrar();"><a href="index.php">Home</a></dt>
</dl>
<dl>
<dt onmouseover="javascript:mostrar();"><a href="catalogo.php">Catálogo</a></dt>
</dl>
<dl>
<dt onmouseover="javascript:mostrar();"><a href="buscar.php">Buscar</a></dt>
</dl>
<dl>
<dt onmouseover="javascript:mostrar();"><a href="tutor.php">Su 1er Midi</a></dt>
</dl>
<dl>
<dt onmouseover="javascript:mostrar('smenu1');">Midi Tutor</dt>
<dd id="smenu1">
<ul>
<li><a href="miditut.php">Inicio</a></li>
<li><a href="midicos.php">Midi Cosas</a></li>
<li><a href="midigm.php">General Midi</a></li>
<li><a href="midique.php">Qué Hacer</a></li>
<li><a href="midicom1.php">Compu 1</a></li>
<li><a href="midicom2.php">Compu 2</a></li>
</ul>
</dd>
</dl>
<dl>
<dt onmouseover="javascript:mostrar();"><a href="mailto:
prolatin@cwpanama.net">Contáctenos</a></dt>
</dl>
<dl>
<dt onmouseover="javascript:mostrar();"><a href="http://www.prolatin.com">Prolatin</a></dt>
</dl>
</div>
But when I translate the code to php, don't work. That's my problem.
Re: Again syntax problems...
Posted: Thu Jul 22, 2010 2:31 pm
by DaiLaughing
You haven't changed the quotes as oscar dog explained. That's the problem. Note the double quotes in his example and the extra slashes as well.
Re: Again syntax problems...
Posted: Thu Jul 22, 2010 2:53 pm
by oscardog
Yeh, in your most recent code post you have added in double quotes but unfortunately you have not escaped them. You must add a \ before a " otherwise it will break the echo.
Re: Again syntax problems...
Posted: Thu Jul 22, 2010 6:32 pm
by jotae
Well, I change the line as you say oscardog:
Code: Select all
echo "<dl><dt onmouseover=\"javascript:mostrar(\"smenu1\");\">Midi Tutor</dt>\n";
But see what happen here, please:
httP://sml.prolatin.com/menu.php
The sub-menu dissapears. Can't access them. The menu don't have any Css treatment yet.
Re: Again syntax problems...
Posted: Fri Jul 23, 2010 1:00 am
by DaiLaughing
I get a 404 error
Re: Again syntax problems...
Posted: Fri Jul 23, 2010 1:13 am
by jotae
Ready now, sorry...
Re: Again syntax problems...
Posted: Fri Jul 23, 2010 4:23 am
by DaiLaughing
The HTML shows you still don't have your PHP right. Don't worry about that though as quotes are probably the hardest single bit to get right in PHP!
<dl><dt onmouseover=
"javascript:mostrar(
"smenu1");">Midi Tutor</dt>
Can you see that the browser will treat the two sets of quotes I have turned red as the start and finish of the attribute value for onmouseover? What you meant to have was:
<dl><dt onmouseover=
"javascript:mostrar('smenu1');
">Midi Tutor</dt>
That is possible by using single quotes in the Javascript and escaped double quotes in the HTML all with double quotes around the ECHO content! Try this:
echo "<dl><dt onmouseover=\"javascript:mostrar('smenu1');\">Midi Tutor</dt>\n";
As I said knowing what to use where is a nightmare. My brain still hurts trying to explain this now. If you want to understand this more try this page:
http://www.yourwebskills.com/phpquotes.html
then do the same structure for all your other code - double quotes in PHP, escaped double quotes in ECHOed HTML and single quotes in Javascript. There are other ways but that was the one I found least difficult in the end.
Re: Again syntax problems...
Posted: Fri Jul 23, 2010 5:26 pm
by jotae
Wow!! Thanks very much!! Working perfect. Really I'm very confussed about syntax in Php because all my life I work with ASP. Regards.
You can see working in
http://sml.prolatin.com/demos.php.
Now I go to change all my pages. Thx!!!