Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with content swap

    Trying to swap out content (in the form of a .php file) on a mouseclick event using javascript. I am completely retarded with this stuff and this seems like it should be such a simple thing to do. Here is what I have so far.

    A .php file (nomadPlaceContent.php) containing the javascript:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script language="JavaScript">
    function nomadPlaceContent() {
    function nomadGetContent(a) {var $contentGot=a; return $contentGot;};
    $defContent=('newsMain.php');
    $content=('$contentGot'+'.php');
    if ($content == $defContent)
    {eval('$defContent');}
    else if ($content != $defContent)
    {eval('$content');}
    ;
    }
    </script>
    </head>

    <body>
    </body>
    </html>


    A menu.php containing the menu for the page and calling the nomadGetContent() function:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <SCRIPT LANGUAGE="JavaScript">

    function movr(k) {
    if (document.images)
    eval('document.img'+k+'.src=img'+k+'_over.src');
    }

    function mout(k) {
    if (document.images)
    eval('document.img'+k+'.src=img'+k+'_static.src');
    }
    function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }
    function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }

    function MM_findObj(n, d) { //v4.01
    var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
    }

    function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }

    </script>

    <style type="text/css">
    #menuContainer{
    float:left;
    margin-top:0px;
    width: 175px;
    background-color:#FFF;
    }

    #menuItemContainer{
    float:right;
    width:175px;
    height:35;
    margin:0px auto;
    }
    </style>


    </head>

    <body>


    <div id="menuContainer">
    <div id="menuItemContainer">
    <a href="#" onclick="nomadGetContent(newsMain);return false;" id="newsMain" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image1','','http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/news_button_over.gif',1)" ><img src="http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/news_button.gif" alt="Gallery News" name="Image1" width="175" height="35" border="0" id="Image1" /></a>
    </div>
    <div id="menuItemContainer">
    <a href="#" onclick="nomadGetContent(nomadEventsContent);return false;" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image2','','http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/events_button_over.gif',1)"><img src="http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/events_button.gif" alt="Gallery Events" name="Image2" width="175" height="35" border="0" id="Image2" /></a>
    </div>
    <div id="menuItemContainer">
    <a href="http://www.themightynomad.com/nomadgallery/main_site/nomadStore.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image3','','http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/store_button_over.gif',1)"><img src="http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/store_button.gif" alt="Gallery Events" name="Image3" width="175" height="35" border="0" id="Image3" /></a>
    </div>
    <div id="menuItemContainer">
    <a href="#" onclick="nomadGetContent(nomadArtistsList);return false;" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image4','','http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/artists_button_over.gif',1)"><img src="http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/artists_button.gif" alt="Gallery Events" name="Image4" width="175" height="35" border="0" id="Image4" /></a>
    </div>
    <div id="menuItemContainer">
    <a href="http://www.themightynomad.com/nomadgallery/main_site/nomadSubmissionContent.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image5','','http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/submit_button_over.gif',1)"><img src="http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/submit_button.gif" alt="Gallery Events" name="Image5" width="175" height="35" border="0" id="Image5" /></a>
    </div>
    <div id="menuItemContainer">
    <a href="http://www.themightynomad.com/nomadgallery/main_site/nomadAboutContent.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image6','','http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/about_button_over.gif',1)"><img src="http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/about_button.gif" alt="Gallery Events" name="Image6" width="175" height="35" border="0" id="Image6" /></a>
    </div>
    <div id="menuItemContainer">
    <a href="http://www.themightynomad.com/nomadgallery/main_site/nomadContactContent.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image7','','http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/contact_button_over.gif',1)"><img src="http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/contact_button.gif" alt="Gallery Events" name="Image7" width="175" height="35" border="0" id="Image7" /></a>
    </div>
    <div id="menuItemContainer">
    <a href="http://www.themightynomad.com/nomadgallery/main_site/nomadLinksContent.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image8','','http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/links_button_over.gif',1)"><img src="http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/links_button.gif" alt="Gallery Events" name="Image8" width="175" height="35" border="0" id="Image8" /></a>
    </div>
    </div>
    </body>
    </html>



    And finally the actual .php index file that calls the menu:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Nomad Gallery Los Angeles</title>
    <LINK href="http://www.themightynomad.com/nomadgallery/styles/nomadMainSiteStyle.css" rel="stylesheet" type="text/css">
    <LINK href="http://www.themightynomad.com/nomadgallery/styles/nomadImageGalleryStyle.css" rel="stylesheet" type="text/css">

    <SCRIPT LANGUAGE="JavaScript">


    function movr(k) {
    if (document.images)
    eval('document.img'+k+'.src=img'+k+'_over.src');
    }

    function mout(k) {
    if (document.images)
    eval('document.img'+k+'.src=img'+k+'_static.src');
    }
    function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }
    function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }

    function MM_findObj(n, d) { //v4.01
    var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
    }

    function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }


    </script>

    </head>

    <body id="mainContainer"
    onload="MM_preloadImages('http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/nomad_logo.gif',
    'http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/news_button_over.gif',
    'http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/events_button_over.gif',
    'http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/store_button_over.gif',
    'http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/artists_button_over.gif',
    'http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/submit_button_over.gif',
    'http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/about_button_over.gif',
    'http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/contact_button_over.gif',
    'http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/links_button_over.gif',
    'http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/rss_button_over.gif',
    'http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/atom_button_over.gif',)">



    <div id="leftSideBar">
    <div id="leftSideBarTop">
    <h2 class="smallBrush"><strong>News Flash</strong></h2>
    <p class="smallLetterGoth"><strong>First Exhibition<br/>
    August 15, 2009
    </strong>
    </p>
    </div>

    <?php include ("nomadGalleryMenu_TestSwap2.php"); ?>
    </div>

    <div id="rightSideBar">

    <div id="rightSideBarTop">
    <div id="rightSideBarTopPosition">
    <h2 class="smallBrush"><strong>New Stuff</strong></h2>
    </div>
    </div>

    <div id="rightSideBarContent">
    <?php include("newStuff.php"); ?>
    </div>

    <div id="feedContainer">
    <a href="http://www.themightynomad.com/nomadgallery/main_site/testindex.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image9','','http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/rss_button_over.gif',1)"><img src="http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/rss_button.gif" alt="rss feed" name="Image9" width="90" height="25" border="0" id="Image9" /></a>

    <img src="http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/white_spacer.gif" width="90px" height="15px" align="center" /><br/>

    <a href="http://www.themightynomad.com/nomadgallery/main_site/testindex.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image10','','http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/atom_button_over.gif',1)"><img src="http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/atom_button.gif" alt="atom feed" name="Image10" width="90" height="25" border="0" id="Image10" /></a>
    </div>

    </div>

    <div id="mainContent">
    <div id="mainContentTop">
    <img src="http://www.themightynomad.com/nomadgallery/main_site/indexpage/images/nomad_logo.jpg" align="left" width="241" height="155" />
    </div>

    <?php include ("nomadPlaceContent.php"); ?>

    </div>

    <div id="footer">
    <h2 class="smallBrush">Customer Service &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Shopping Cart</h2>
    </div>





    </body>
    </html>



    I know this is a lot but I really would love some help!!

    Thank you in a big way!!!

    -Craig

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Not a PHP problem.
    To use an onclick event and dynamically load content requires the use of a client side technology called AJAX. Its simply javascript that allows transparent loading of data.

    Moving to JS > AJAX forum.

    BTW, you'll be wanting to wrap that code in [code][/code] tags.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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