I'm trying to get the value of the li the client clicked on and 'transform' that into a php variable.
<ul class="dropdown-menu" role="menu">
<li id="banAppeal"><a href="#">Ban Appeal</a></li>
<li id="banAppeales"><a href="#">Spanish Ban Appeal</a></li>
</ul>
If they click on "Ban Appeal", a form appears:
$(document).ready(function(){
$("#banAppeal").click(function(){
$("table#unban").show();
$("table#default").hide();
}); });
How can I get the value of whatever they click and put that in a PHP Variable? I know .val() does not work.
To send a variable or a value to PHP, you either need to utilize
POST
GET
AJAX
here are some example codes in how you can do so.
http://iviewsource.com/codingtutorials/learning-how-to-use-jquery-ajax-with-php-video-tutorial/
Javascript is client side, and PHP server side. So you can't use JavaScript / JQuery with PHP Take a look to AJAX, it can help you
If I got your need, "the value of whatever they click" it could be achieved like this.
$(document).on("click", ".yourClassControl", function(e){
e.preventDefault();
var dt={
ObjId:$(this).attr("id"), //This is the variable you will //send to PHP as you asked... NOTE: you said "the value of whatever they click" //so, for each DOM element you will have different way to retrieve the id
otherData:$(this).val()
};
var request =$.ajax({//http://api.jquery.com/jQuery.ajax/
url: "ADMIN/ADMIN.php",
type: "POST",
data: dt,
dataType: "json" //I use JSON in this example
}); //End of $.ajax({...
request.fail(function(jqXHR, textStatus) {
alert("Request failed: " + textStatus);
});//End of fail(function....
request.done(function(dataset){//This will receive the information //from your PHP page and use this information to control the beheavior of your //DOM elements
for (var index in dataset){
responseFromPHP=dataset[index].responPHP;
}//End of for
$('.wrapper').html(responseFromPHP);
}); //End of request.done(....
}); //Endo of $(document).on("click", ...
PHP side:
I have used AJAX whit JSON response from PHP. ADMIN.php
$ObjEvn=$_POST["ObjId"];//Here is your question.... ObjId comes from javascript // and $ObjEvn is your php variable
if($ObjEvn==="banAppeal"){
//Do something for banAppeal element
}
elseif($ObjEvn==="banAppeales"){
//Do something for banAppeales element
}
//Now return what you want to javascript
$arrToJSON = array(
"responPHP"=>"your value or string or code"
);
return json_encode(array($arrToJSON));