0

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?

Jon Adams
25.3k18 gold badges85 silver badges122 bronze badges
asked Dec 6, 2011 at 14:36
1
  • Could we see writetofile perhaps? Commented Dec 6, 2011 at 14:39

1 Answer 1

4

Looks like you have incorrectly quoted the string inside the JavaScript function call. Change them from double to single quotes. (This assumes $file is being passed to the function as a string, and isn't supposed to have been defined somewhere in JavaScript as a symbol).

<input type="submit" onclick="writetofile('<?php echo $file; ?>')" value="Work " />
aziz punjani
25.8k9 gold badges49 silver badges56 bronze badges
answered Dec 6, 2011 at 14:39
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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