Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6217037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:21:20+00:00 2026-05-24T07:21:20+00:00

Ignore the previous question – this is the only bit I don’t understand now,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:21:22+00:00Added an answer on May 24, 2026 at 7:21 am

    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.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <script>
    function changeText(choice){
            var xmlhttp;
            if (window.XMLHttpRequest)
              {// code for IE7+, Firefox, Chrome, Opera, Safari
              xmlhttp=new XMLHttpRequest();
              }
            else
              {// code for IE6, IE5
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
              }
            xmlhttp.onreadystatechange=function()
            {
              if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                var res=xmlhttp.responseText;
                document.getElementById("myText").innerHTML=res;
                }
              }
            xmlhttp.open("GET","getMyText.php?file="+choice,true);
            xmlhttp.send();
            }
    </script>
    
    <select onChange="changeText(this.value)">
    <option value="opt1">Option1</option>
    <option value="opt2">Option2</option>
    </select>
    <textarea id="myText"></textarea>
    
    </body>
    </html>
    

    EDIT: Using jQuery

    the HTML:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
    </head>
    
    <body>
    <script>
    function changeText(choice){
    $.get('so_getfile.php?file='+choice, function(data) {
      $('#myText').html(data);
    });
            }
    </script>
    
    <select onChange="changeText(this.value)">
    <option></option>
    <option value="1">Option1</option>
    <option value="2">Option2</option>
    </select>
    <textarea id="myText"></textarea>
    
    </body>
    </html>
    

    the PHP web service:

    <?php
    $array = array('file1.txt', 'file2.txt');
    $file = $array[$_GET['file']-1];
    $text = fopen($file,'r');
    if ($text) {
        while (($buffer = fgets($text, 4096)) !== false) {
            echo $buffer;
        }
        if (!feof($text)) {
            echo "Error: unexpected fgets() fail\n";
        }
        fclose($text);
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is a folo to a previous question I asked about how to
This question has been asked many times before but none of the previous ones
Is there a way to use cin.clear() or cin,ignore() for ONLY the previous line
This maybe a continuation from 2 of my previous question, or maybe it's a
following this question : Best approach for oldschool 2D zelda-like game Thank to previous
From my previous questio n this was the solution I am accepting: INSERT IGNORE
In my previous question here, I didn’t understand how to solve my problem. Linq
Take this example code (ignore it being horribly inefficient for the moment) let listToString
The Situation (Ignore this it is boring): I have reports that I created using
I'm sure this is a stupid easy question, but with HTML I can never

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.