2

Is there any way to refrence a .txt file with a textarea? what I've tried so far dosen't work I do not want to use php or ajax, just bare html+css+javascript

  <textarea rows="16" cols="100" name="textdata" href ="hokuco.com/home/livedoc/user.txt"></textarea><br/>

2

2 Answers 2

1

You can read the file with javascript (see link) and then add it to the textarea.

https://stackoverflow.com/a/14446538/2550732

EDIT:

Javascript:

function readTextFile(file)
{
    var rawFile = new XMLHttpRequest();
    rawFile.open("GET", file, false);
    rawFile.onreadystatechange = function ()
    {
        if(rawFile.readyState === 4)
        {
            if(rawFile.status === 200 || rawFile.status == 0)
            {
                var allText = rawFile.responseText;
                alert(allText);
            }
        }
    }
    rawFile.send(null);
}

Jquery:

$.ajax({
    url : "helloworld.txt",
    dataType: "text",
    success : function (data) {
        $(".text").html(data);
    }
});
5
  • I don't think that's what they want Jan 14, 2016 at 12:52
  • 2
    Put this type of link in Comment
    – Moumit
    Jan 14, 2016 at 12:54
  • your right I want to refrence my text but also save to it with php
    – parseguy
    Jan 14, 2016 at 12:55
  • can you accomplish this with bare html?
    – parseguy
    Jan 14, 2016 at 12:57
  • 1
    @parseguy:- No you cannot. Jan 14, 2016 at 12:57
0

You can use JQuery and try like

$(".text").load("myText.txt");

Check the jQuery.load()

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.