Vote count:
0
Summary
Currently I have a webpage in which I am running some javascript to basically allow a user to create an UL list. I want to then process that list, saving it to a file on the server which will need to be done with PHP of course.
Goal
The overall goal that I am hoping to solve is how to embed php within javascript. Keep in mind that the javascript itself is being echoed from the html page so everything will be surrounded by single quotes of course.
What I have tried
function ShuffleList(){
var ul = document.getElementById("playlist");
for (var i = ul.children.length; i >= 0; i--)
ul.appendChild(ul.children[Math.random() * i | 0]);
}
function test(){
var ul = document.getElementById("playlist");
var playlist = "";
for (i = 1; i < ul.children.length; i++){
var item = ul.childNodes[i];
playlist += item.innerHTML + String.fromCharCode(13);
}
playlist = playlist.slice(0, -1);
jsvar = \'<?php echo $playlist;?>\';
alert(jsvar);
}
The variable playlist is generated perfectly fine. At the end I am trying to do something very simple with the playlist variable. I am simply, for now, trying to just pass the playlist variable int a php script which will then echo it back as a variable for me to display as an alert.
The above code will result in a popup box that has the literal displayed. For some reason it isn't recognizing that it is a php script but rather treating it as a string.. Am I missing something simple or totally obvious?
I have looked at many posts on SO but all that seem like they would work by using a similar idea as above don't..
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire