So I have this unordered list of items that is made from querying a mysql database
<ul>
<li>apple</li>
<li>orange</li>
<li>pear</li>
</ul>
I want there to be an onclick event that will pass 'apple' when I click apple and 'orange' when I click orange.
I also want to pass this information to another page through php. So this is my idea for the javascript function.
<script>
function passName(obj){
var pass = "<?php $x= " + obj.getName() + " ?>";
}
function getname(obj){
return 'string';
}
</script>
My Question: is there a method that exists within JavaScript that allows me to pull the raw string value of my unorderedlist without writing my own function? If I have to write my own JavaScript function, is there a way to set the 'name' strings automatically, while the list is populating?
<ul>. "set the 'name' strings automatically, while the list is populating" . What strings are you referring to?var pass = "<?php $x= " + obj.getName() + " ?>";will never work - you fundamentally mis-understand how the web works. That code will execute before your page loads, which is when PHP was executing. Then your HTTP request ended and it stopped. If you want PHP to execute again you have to make another request to the server - either through a postback or an ajax request, and send your data in it