lovephp Posted October 11, 2012 Share Posted October 11, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/269366-switch-content-not-working-please-help-fix/ Share on other sites More sharing options...
jazzman1 Posted October 13, 2012 Share Posted October 13, 2012 Don't make double posts, please. Quote Link to comment https://forums.phpfreaks.com/topic/269366-switch-content-not-working-please-help-fix/#findComment-1384915 Share on other sites More sharing options...
codefossa Posted October 13, 2012 Share Posted October 13, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/269366-switch-content-not-working-please-help-fix/#findComment-1384940 Share on other sites More sharing options...
lovephp Posted October 13, 2012 Author Share Posted October 13, 2012 i did not double post guys. its different and the above working example not working i guess? Quote Link to comment https://forums.phpfreaks.com/topic/269366-switch-content-not-working-please-help-fix/#findComment-1384971 Share on other sites More sharing options...
codefossa Posted October 14, 2012 Share Posted October 14, 2012 i did not double post guys. its different and the above working example not working i guess? It was tested and working in Firefox as well as Google Chrome. Quote Link to comment https://forums.phpfreaks.com/topic/269366-switch-content-not-working-please-help-fix/#findComment-1385084 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.