SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: simple question

  1. #1
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple question

    I have this code that works

    HTML Code:
    window.onload= function run() {
    	montre();
    	montreMenu(3);
    but when i change it for this
    HTML Code:
    window.onload= function run() {
    	montre();
    	montreMenu(<?php $_GET['menu_ID'];?>);
    im trying to make it work with a link index.php?menu_ID=3

    but it wont work...does anyone know why?

    Thanks

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where is that code? Is it in a .js file? A .php file?
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is javascript in a php file

    here's the entire script
    HTML Code:
    <script type="text/javascript">
    <!--
    window.onload= function run() {
    	montre();
    	montreMenu(3);
    }
    function montre(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';}
    }
    function montreMenu(id) {
    	document.getElementById('smenu'+id).style.display='block';
    }
    //-->
    </script>
    changing the number in this line makes that menu opened when u open the page
    HTML Code:
    	montreMenu(3);
    i just want to write the javascript acording to the link you type:

    if u type the 2nd menu a php variable will be send and change the number in the javascript, with a link like this: index.php?menu_ID=2

    but this doesnt seem to work:

    HTML Code:
    <script type="text/javascript">
    <!--
    window.onload= function run() {
    	montre();
    	montreMenu(<?php $_GET['menu_ID'];?>);
    }
    thanks

  4. #4
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i managed like this:

    PHP Code:

    <?php
    $mnu 
    $_GET['menu_ID'];
    ?>
    <script type="text/javascript">
    <!--
    window.onload= function run() {
        montre();
    <?php    echo "montreMenu"."(".$mnu.")"?>
    }
    function montre(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';}
    }
    function montreMenu(id) {
        document.getElementById('smenu'+id).style.display='block';
    }
    //-->
    </script>
    thanks

  5. #5
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •