0

I have a school project I am trying to complete. Its a fairly easy one, but due to my professors being in another country I am neither able to get answers from them frequently nor quickly.

I am trying to create a webpage that makes it so that when I click a link it causes it to load and append a .txt file underneath the sub navigation without changing any of the page.

This is my incomplete javascript code:

<script type="text/javascript" src="js/jquery-1.8.1.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    var massage = ('massage.txt')
    $('.selection').click(function() {
        $('.selection').append('massage');

    });
});
</script>

This is my HTML:

  <div id="content">
            <div id="spaselection">

                    <p class="selection">
                    Massage
                    Facials 
                    Laser Hair Treatment/Electrolysis 
                    Nails
                    </p>

            </div>
9
  • Where's the txt file located? Something you need to upload, or somewhere on the web? Commented Apr 8, 2014 at 23:47
  • Its something I need to upload Commented Apr 8, 2014 at 23:49
  • 1
    Check stackoverflow.com/questions/19038919/… Commented Apr 8, 2014 at 23:53
  • I am afraid I don't understand what it is they're explaining?? I am not trying to upload a txt file to myself from a website I am trying to make it so when they click the word "Massage" it puts the text from the "massage.txt" file underneath it? Commented Apr 9, 2014 at 0:02
  • But where is massage.txt coming from? From what you mentioned earlier, you said the user's computer has this file. Well they would need to upload it into the browser for it to be handled. Commented Apr 9, 2014 at 0:05

1 Answer 1

0

If you're talking about a file named 'massage.txt' in the same folder as your webpage, then there is a simple solution that involves only HTML. I'm sure you're aware of iFrame. You can use that to upload files from your folder, as well as websites not owned by you. Example:

<iframe src="massage.txt" type="text/plain"
content="file" class="upload" width="whateverPX"
height="whateverPX">If you see this message, 
massage.txt does not exist or your browser doesn't support iframes.</iframe>

Of course, you can style it whatever you want and change the size of it. Here is my finished version:

<iframe src="/student/jason/beatrice/massage.txt" type="
text/plain" content="file" class="upload" width="900px" height="800px" frameborder="0" 
script="autoUpload();">
Your browser does not support iFrames
</iframe>
<noscript>Your browser does not support Javascript.</noscript>

And yeah, I invented the iFrame type. That doesn't really matter. What matters is, it works. Tested in most major browsers and approved. According to W3Schools, iFrames are supported in at least 5/6 major browsers. Supported in Chrome, Firefox, IE, Edge, Safari, etc.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.