views:

27

answers:

1

Hi

I'm sure this is possible in php. I have several css files located in a folder on my server. I wish to list these files in a drop down menu located on a php page.

When the user selects one of these files in the dropdown, a textarea on the same page is populated with the source code of that css file.

Struggling with this one, any help much appreciated

Thanks

Rifki

A: 

Without a reload?.. You'd have to use Ajax to do this.

with jQuery it would look something like this:

$(document).ready(function() {
  $('#mySelector').click(function() {
    $.get('./css/' + this.val(), function(data) { $('#myTextbox').val(data); });
  }
});
Fosco
Thanks, would rather not reload page. Could you explain a bit further. Would I create a drop down entitled mySelecter?
Rifki
Your drop down box would have an ID attribute matching "mySelector" in this example, which could be changed to whatever you like. The textarea would have an ID attribute of "myTextbox". jQuery finds an element by ID with the $('#id') syntax.
Fosco
Thars great thanks. Forgot to mention. would this code automatically remove the existing text in text area from previous css file, or would i need to clear it first
Rifki
that would replace what was there.
Fosco
ok thanks for your comment
Rifki
HI I keep getting 'this.val is not a function' on the code snippet above. Anybody have an idea whythanks
Rifki