I have some php, html and JS code:
$files = getDirectoryList("/home/uploads/");
foreach($files as $file)
{
?>
<input type="submit" onclick="writetofile("<?php echo $file; ?>")" value="Work " />
<?php
echo $file;
}
When I click on “Work” the writetofile doesn’t get called which is defined at top in HTML head tag script. Why?
Looks like you have incorrectly quoted the string inside the JavaScript function call. Change them from double to single quotes. (This assumes
$fileis being passed to the function as a string, and isn’t supposed to have been defined somewhere in JavaScript as a symbol).