I have Html Form variables that get stored in a FirstName.json in a directory called SavedPB .
<form action="save_json.php" method="post">
First name: <input type="text" name="firstname" /><br />
Last name: <input type="text" name="lastname" /><br /><br />
<input type="submit" id="submit" value="Send" />
</form>
I list the files in that directory with the following code:
<?php
if ($handle = opendir('SavedPB')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
$entry = substr($entry, 0, strlen($entry) - 5);
echo "
<tr>
<td id=\"cel1\">$entry\n</td>
<td id=\"cel1\"><button id=\"btnLoad\">Load Json</button></td> <br />"
;
}
}
closedir($handle);
}
?>
This php script removes the .json extention from the view and it has a button after each found file.
The button fires off a jquery script to load the stored json variables back into the form fields:
$(document).ready(function() {
$("#btnLoad").click(function(){
$.getJSON("SavedPB/FirstName.json", function(data) {
$('input[name="firstname"]').val(data["firstname"]);
$('input[name="lastname"]').val(data["lastname"]);
});
});
});
I'm facing 2 problems that i can't seem to resolve .
- The php echoed list
when clicked on the button next to echoed list item I need to get the variable of the name next to the button.
Example :
FirstName1 button
Firstname2 button
if clicked on the button next to FirstName2 i need the name variable to be changed in the jquery script to be set to $.getJSON("SavedPB/FirstName2.json", function(data)
- It seems to load the variables back into the form fields only when I hit the button next the first in the list
If i click the button next to Firstname1 it loads the json back into the form but not when i click the button next to FirstName2