1

I'm trying to save the value of "src" in a .txt file which is on my local disc at C:\hi\data.txt.

I think the problem is in id: $(this).find('.src').val() because src is created after a button click with the help of some JS.

I'm not fully familiar with jQuery and JS, but this is what I managed to do. The "Add Video" button works fine.

<body>

<input id="input" type="text" name="Youtube Source" />
<button id="button" onclick="addVideo();">Click to add video!</button>
<button id="button1">Click to save!</button>

<div id="ytContainer"></div>

</body>

<script>
var x;
function addVideo() {
    x = document.createElement("EMBED");
    x.setAttribute("src", 'https://www.youtube.com/v/' + input.value);
    document.getElementById("ytContainer").appendChild(x);
}
</script>

<script>
$("#button1").click(function ()
{
    $('#form_addjts').submit(function () {
        writeToFile({
            id: $(this).find('.src').val(),
        });
        return false;
    });
    function writeToFile(data) {
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        var fh = fso.OpenTextFile("C:\hi\data.txt", 8);
        fh.WriteLine(data.src);
        fh.Close();
    }
});
</script>
Ivar
  • 6,138
  • 12
  • 49
  • 61
Nick White
  • 35
  • 9

1 Answers1

0

You stated the problem if the value of the src, well there is no element with the "src" class in your example. If you were talking about the embed src, you can $('#ytContainer').find('embed').attr('src'); If there is indeed an element with the class "src" that we don't see in the form that we don'T see either, the problem is probably something else.

Bene
  • 1,875
  • 14
  • 14