Jump to content

Switch Content Not Working Please Help Fix


lovephp

Recommended Posts

its not fetching results and also giving error, could someone see whats wrong?



<?php
$contentVar = $_POST['contentVar'];
if ($contentVar == "con1") {
   echo "My default content for this page element when the page initially loads";
} else if ($contentVar == "con2") {
   echo "This is content that I want to load when the second link or button is clicked";
} else if ($contentVar == "con3") {
   echo "Content for third click is now loaded. Any <strong>HTML</strong> or text you wish.";
}
?>


<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.1.js"></script>
<script language="Javascript" type="text/javascript">
<!--
function swapContent(cv) {
   $("#myDiv").html('<img src="loader.gif"/>').show();
   var url = "test.php";
   $.post(url, {contentVar: cv} ,function(data) {
   $("#myDiv").html(data).show();
   });
}
//-->
</script>
<style type="text/css">
#myDiv{
   width:200px; height:150px; padding:12px;
   border:#666 1px solid; background-color:#FAEEC5;
   font-size:18px;
}
</style>
</head>
<body>
<a href="#" onclick="return false" onmousedown="javascript:swapContent('con1');">Content1</a>
<a href="#" onclick="return false" onmousedown="javascript:swapContent('con2');">Content2</a>
<a href="#" onclick="return false" onmousedown="javascript:swapContent('con3');">Content3</a>
<div id="myDiv">My default content for this page element when the page initially loads</div>
</body>
</html>

Link to comment
Share on other sites

Here's a working example.

http://xaotique.no-ip.org/tmp/6

 

<?php

if (isset($_POST['con']))
{
   switch ($_POST['con'])
   {
       case "con1":
           die("Clicked Link 1");
       case "con2":
           die("Clicked Link 2");
       case "con3":
           die("Clicked Link 3");
   }
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
   <head>
       <title>Temporary Page</title>
       <meta http-equiv="content-type" content="text/html;charset=utf-8" />
       <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>

       <style type="text/css">
           a.sublink
           {
               text-decoration: none;
               color: #0000AC;
               float: left;
               margin-left: 15px;
           }
       </style>

       <script type="text/javascript">
           $(document).ready(function()
           {
               $(".sublink").click(function(e)
               {
                   e.preventDefault();

                   $.post('', { con: $(this).attr("name") }, function(data)
                   {
                       $(".result").html(data);
                   });

                   return false;
               });
           });
       </script>
   </head>

   <body>
       <a href="#" class="sublink" name="con1">First</a>
       <a href="#" class="sublink" name="con2">Second</a>
       <a href="#" class="sublink" name="con3">Third</a>
       <br /><br />
       <b>Result:</b> <span class="result"><span style="color: #990000;">Click A Link</span></span>
   </body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.