Below I have a function which saves variable on a PHP form to a list of objects in javascript
a.js
function save()
{
var oldItems = JSON.parse(localStorage.getItem('itemsArray')) || [];
var newItem =
{
'num' : document.getElementById("num").value,
'methv' : document.getElementById("methv").value,
'q1' : document.getElementById("q1").value,
'q2' : document.getElementById("q2").value,
'q3' : document.getElementById("q3").value,
'q4' : document.getElementById("q4").value,
'comm' : document.getElementById("comm").value
};
oldItems.push(newItem);
localStorage.setItem('itemsArray', JSON.stringify(oldItems));
}
How can i display the contents in my php page so i can edit them? (examples of what it will look like printed out is appreciated)
Edit*
These are the values that will be added to the object
<form action="" method="post" enctype="multipart/form-data">
<select name="methv" class="textfields" id="methv" style="width:110px" >
<option value= "dont know">dont know </option>
<select name="q1" class="textfields" id="q1" style="width:50px" >
<option value= "-">-</option>
<option value= "L">L</option>
<select name="q2" class="textfields" id="q2" style="width:50px" >
<option value= "-">-</option>
<option value= "L">L</option>
<select name="q3" class="textfields" id="q3" style="width:50px" >
<option value= "-">-</option>
<option value= "L">L</option>
<select name="q4" class="textfields" id="q4" style="width:50px" >
<option value= "-">-</option>
<option value= "L">L</option>
<textarea rows="4" cols="40" id="comm" name="comm" style="width:300px"><?php echo $post['addcomment'] ;?></textarea>
</form>
I have only imported a.js and <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
You'll have to submit the data to the server via a GET or POST request in order for a PHP script on the server to work with that data. As long as it's just in JavaScript and localStorage, the server (and, hence, PHP) has no idea it exists.
You seem to be confusing the roles of PHP and Javascript.
PHP is server-side, meaning that it renders the page (and does any calculations, database calls, etc, if necessary), and then outputs HTML. This is the end of PHP's involvement in a web page.
Javascript is client-side, meaning after a page has been loaded and rendered in a browser, Javascript can get to work modifying elements of the page, if you'd like.
You haven't included any information about the current page structure, so there is nothing we can offer to help you modify your page content using javascript.
PSTHow about this ?
When you submit your code you rub the function save.
<form action="" onsubmit="save()" method="post" enctype="multipart/form-data">
And you add to you form tag something like the following
<textarea id="SendToPhp" style="display : none"></textarea>
And in you save function you add this as the end
document.getElementById('SendToPhp').innerHTML = object;
Or something like that !
But i this this is what you are missing!
add the following to the end of your form <input type="submit" value="Send To PHP" />
but keep it inside your <form>
tag so place it right before </form>
When you click this button you will be send to the php page that should be in the action ex action = "readjs.php"
and in that page do print_r($_POST)
The values you need will be stored in the POST.
If you want to do it without reloading the page then you must look in more into AJAX
Hope this helped in any way.
EDITED CODE, Should be $_POST was previously $_GET