Ignore the previous question – this is the only bit I don’t understand now, everything else works:
UPDATE: ALMOST WORKING:
$(document).ready(function(){
$("#fileSelect").click(function(){
var myString = <?php
$array = array('homeText.txt', 'anotherText.txt' /*ETC*/);
$file = $array[/*JS SELECTED INDEX*/];
$path = '../txt/'.$file;
include $path;
?>
tinyMCE.execCommand('mceReplaceContent',false,myString);
});
});
QUESTION: How would I pass the index of the selected item in the dropdown into that php code (from the jquery), so that I could call the appropriate item in the array to return the right file.
You can use AJAX to read in the files.
You’ll add an ‘onchange’ function to the dropdown, so that each time the user changes it, the ajax function will fire (retrieving the file contents) and insert that text into the textarea.
Here is a similar situation that used PHP in the background to generate the text…but you can modify that so that it just calls the appropriate file based on the selection (or, if you prefer, make a single PHP file that echoes the right text based on some GET variable [or POST if you like])
Populating dropdown – PHP Ajax MySQL
you’d also change the destination of the data from the dropdown to your textarea. So here’s some code…it uses the hypothetical getMyText.php (passing it the ‘file’ variable) and expects text back, which it will then place in the textarea.
EDIT: Using jQuery
the HTML:
the PHP web service: