ex.
<li value="123">123</li>
<li value="456">456</li>
howto pass value <li value="xxx">
to a php session when clicking on <li value ="xxx">
You would create a file that looks like this
// update_session.php
<?php session_start();
if (isset($_POST["val"])){
$_SESSION["val"] = $_POST["val"];
}
Then for your html you would have (note I changed attribute to a data-value because value is not a valid attribute for li whereas the data- prefix attributes are valid.)
<ul id ='my_ul'>
<li data-value="123">123</li>
<li data-value="456">456</li>
</ul>
And you jquery (in a document ready block) would look like this.
$('#my_ul').on("click", "li", function(){
$.ajax("update_session.php",{method:"post", data:{val:$(this).attr("data-value")}});
});
<li>
doesn't have a value
attribute. However, you could put a button inside the list item and send that. For instance:
<li><button name="button1" value="123">123</button></li>
<li><button name="button2" value="456">456</button></li>
Then just style button
to not look like a button.
If you include these elements in a form, their values would be accessible in your PHP script through either the $_POST
or $_GET
arrays depending on how you send it.