Discussion: document.GetElementsByName not working
2 messages from 2 displayed.
//= Settings::TRACKING_CODE_B ?> //= Settings::TRACKING_CODE ?>
Hi Douglas,
did you check the "Console" tab in the developer tools (F12) for error messages?
Usually, you can find what's wrong there.
I wouldn't use the name
attribute to select items, this is
usually done by assign a class, e.g. a .selected
class. I'd also
use a single JavaScript file to handle all of that. It's always a good idea to
separate JS code from PHP code because it's difficult to find an error
otherwise.
I'm not sure why do you use the <input>
element to render
images? I'll use the <img>
element instead.
public function render()
{
echo
'<img src="' . $this->url . '" alt="" id="' . $this->id . '" class="album-image" />';
}
I assigned the .album-image
class to the images so I can
manipulate with them in JS easily.
Your JS file can look as follows:
let images = document.getElementsByClassName('album-image'); // selects all the images
for (let image of images) { // iterates through all of them
image.onClick = function() { this.classList.add('selected'); }; // adds the onClick event to all of them
}
I'm not sure about your update()
PHP function. It would be a big
help if you specified what the application should do.
2 messages from 2 displayed.