Click here to Skip to main content
15,891,621 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
<select name="s1">
      <option value="" selected="selected">-----</option>
  <?php 
       foreach(glob(dirname(__FILE__) . '/txt/*') as $filename){
       $filename = basename($filename);
       echo "<option value='" . $filename . "'>".$filename."</option>";
    }
	

?>

</select>


	
<form action="save_selected.php" method="post">
    <input type="submit" name="myfile" value="ok" />
</form>



<?php
var name = document.getElementById("myText").value;
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt =  $filename;
fwrite($myfile, $txt);

fclose($myfile);
?>


What I have tried:

Right now It just save right away. Then I tried to split up the code into 2 files. How can the button detect the selected file into a var! and then read the save code?

Is it possible to keep all code in one file, and use a loop. First read the files into combobox (stop code) press OK, (start code "save")?
Posted
Comments
Richard Deeming 23-Apr-20 11:47am    
Unclear. You're mixing up PHP and Javascript (trying to call document.getElementById from the server-side code). You've got a <select> outside of your <form>, so that the selected value won't be sent to the server. You're referring to elements and variables which don't exist.

I think you need to look at some basic PHP tutorials. In particular, focus on the separation of code between the server and the client.
Mark Rene Jensen 23-Apr-20 13:45pm    
I just found out it, I just read on the net you can't mix php and html/javascript together! okay thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900