0

i have recently started coding in PHP and im wondering how i can show a div defined in the adress bar (example: www.yourwebsite.com/index.php?divtoshow=home)

The div is hidden with css, display:none;

then i want it to display the home div

i have tried using jquery, but i cant seem to get the variable to be implamented into the script

I already have the following for when i click the home icon:

$(".chome").click(function(){
    $("#home").show(500);
    });
  • http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values – Ian Dec 04 '12 at 00:34
  • Added that info, im using display:none to hide it from the beginning – Martin Claesson Dec 04 '12 at 00:35
  • What is generating the URL? I ask because if it's just a call to your PHP page, then your PHP can generate the markup. Otherwise, if it's coming from javascript and solely intended to hide the div, why are you going through PHP? – RonaldBarzell Dec 04 '12 at 00:35
  • Is the ID of the supposed to be the value of "divtoshow"? Meaning you would have a div that looks like
    already set up in the DOM somewhere?
    – Paul Richter Dec 04 '12 at 00:36
  • @MartinClaesson Ok. I think dbaseman's answer is probably the best solution for this. – Paul Richter Dec 04 '12 at 00:41

1 Answers1

4

First, get the name from the query string:

<?php $divtoshow = $_GET["divtoshow"]; ?>

Second, add some JQuery to display the div on page load:

<script>
    $(document).ready(function() {
        $("div[id=<?php echo $divtoshow; ?>]").show();
    });
</script>
McGarnagle
  • 101,349
  • 31
  • 229
  • 260