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>