dcsimg
Results 1 to 2 of 2

Thread: Calling a PHP function from "onclick"?

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    4,893

    Calling a PHP function from "onclick"?

    I have a web page that isn't working the way I need it to. My question is: I've researched into whether you can you call a PHP function from an "onclick" attribute? Below is my code and nothing is happening when I click on a menu link. I don't know if I'm completely on the wrong path or if I just have some code in the wrong places.

    Code:
    <?php 
        $rootDir = "C:/apache/htdocs/resume/";
        $section = "pages/summary.php";
    ?>
    
    <!doctype html>
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head lang="en">
            <title>Resume of Blake McKenna</title>
        </head>
    
        <body>
            <header>
                <div class="main">
                    <ul>
                        <li onclick="checkMenuOption(1)" class="initial" <a class="menu" href="#">Summary</a></li>
                        <li onclick="checkMenuOption(2)" class="initial" <a class="menu" href="#">Technical Skills</a></li>
                        <li onclick="checkMenuOption(3)" class="initial" <a class="menu" href="#">Experience</a></li>
                        <li onclick="checkMenuOption(4)" class="initial" <a class="menu" href="#">Education</a></li>
                        <li onclick="checkMenuOption(5)" class="initial" <a class="menu" href="#">Certifications</a></li>
                        <li onclick="checkMenuOption(6)" class="initial" <a class="menu" href="#">Contact Me</a></li>
                    </ul>
                </div>
            </header>
    
            <div class="sections">            
                <?php include $rootDir . $section; ?>
            </div>
            
            <script>
                function checkMenuOption(opt) {
                    switch(opt.tostring) {
                        case '1':
                            <?php $section = "pages/summary.php"; ?>
                            break;
                        case '2':
                            <?php $section = "pages/skillset.php"; ?>
                            break;
                        case '3':
                            <?php $section = 'pages/experience.php'; ?>
                            break;
                        case '4':
                            <?php $section = "pages/education.php"; ?>
                            break;
                        case '5':
                            <?php $section = "pages/certifications.php"; ?>
                            break;
                        case '6':
                            <?php $section = "pages/contact.php"; ?>
                            break;
                    }  
                }
            </script>
        </body>
    </html>
    Last edited by blakemckenna; Oct 4th, 2018 at 01:11 PM.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width