I have a problem with the variables, that I want to pass through ajax to php.
In an php file, I generate some divs with id and name attributes.
livesrc.php
echo "<div class=\"search-results\" id=\"" . $softwareArray['Sw_idn'] . "\"
name=\"" . $softwareArray['SoftwareName'] . "\"
onclick=\"addBasket(this.id, this.name)\" >
" . utf8_encode($softwareArray['SoftwareName']) . "</div>";
The relevent part is this:
onclick="addBasket(this.id, this.name)
Sorry for the escapes, in html the div looks like:
<div class="search-results" id="235"
name="Adobe Acrobat Writer 9.0 Professional"
onclick="addBasket(this.id, this.name)">...</div>
This looks okay, but in the js "addBasket", the variable sw_name is not set. (undefinded)
The JS in the head section:
<script type="text/javascript">
function addBasket(sw_id, sw_name)
{
alert(sw_name);
$.post("assets/basket.php",{sw_id: sw_id, sw_name: sw_name}, function(data)
{
$("#basket").html(data);
});
}
</script>
The sw_id is set, but the sw_name is not working. Is the call in html with "this.name" correct?