I'm working on an application that renders a collage of images (album covers). However, whenever I run this code, the update function doesn't send an alert, so I'm assuming it cannot find any elements with the name I assigned with the onClick function. Why is that? The render function works fine and assigns the name properly. The classes are in PHP, but the user input (click events, etc.) is handled in Javascript.
Here is the render function which is located in the Album class:
public function render()
{
echo
"<script>function setName(id){document.getElementById(id).setAttribute('name','selected');}</script>" .
"<input type='image' onClick='setName(this.id)' id='$this->id' src='" . $this->url . "'/>";
}
Here is the update function which is located in the Chart class (manages Album objects):
public function update($url)
{
echo
"<script type='text/javascript'>" .
"var clicked = document.getElementsByName('selected');" .
"alert(clicked[0].id);" .
"document.getElementById(clicked[0].id).src='" . $url . "';" .
"clicked[0].setAttribute('name','');" .
"</script>";
}
document.getElementsByName('selected');"
ordocument.getElementsByName('select');"