0

I am trying to append this php code using jquery. Is it possible? I have

<script>
var myUrl = $("#categories").val();

   $("<?php include('" + myUrl + "') ?>").appendTo( ".imgList" );
</script>

Is that the correct way of doing it? or is it just impossible? Any help is appreciated thanks.

Edit This is the code I am using to load the content.

var myUrl = $("#categories").val();

 $( ".imgList" ).load(myUrl);

But it doesn't change when I change categories.

Edit2

                <select id="categories" name="categories">
                <option value="">Choose a category</option>
                <option value="page1.html">Real Estate</option>
                <option value="page2.html">Commercial Auto</option>
                <option value="page3.html">Beauty/Salon</option>
                <option value="4">Health</option>
                <option value="5">Construction</option>
                <option value="6">Legal</option>
                <option value="7">Furniture</option>
                <option value="8">Food</option>
            </select><!-- end id="categories" -->
Andres Rivera
  • 97
  • 2
  • 7

1 Answers1

2
$("#categories").on('change', function(){
    $( ".imgList" ).load( $(this).val() );
}).trigger('change'); // trigger 'change' on page load if you want to load categories based on whichever is selected by the HTML outputted
Popnoodles
  • 28,090
  • 2
  • 45
  • 53