Page 1 of 1

Onclick event

Posted: Tue Apr 16, 2019 9:34 pm
by alex4orly
I have a page here : http://communitylifestyleaccommodation. ... board.html
When a name is clicked in the buttons, I trigger the onclick and created a show picture of the relevant person

But now, I want to get the text of the button clicked and show it as a label under that picture.

I must be doing something wron, it doesn't show the text - here below is the function I created.
I inserted a text item under the picture, ID=Text38

<script>
function ShowName()
{
var buttonid = event.srcElement.id; // works ok
var buttontext = document.getElementById(buttonid).value; // works ok
alert(buttontext); // Show the text
document.getElementById('Text38').setAttribute("value", buttontext); // Does NOT WORK
}
</script>

Any suggestions
Thanks

Re: Onclick event

Posted: Wed Apr 17, 2019 6:10 am
by Pablo
A text object does not have a 'value' property. This is only available for form elements.
https://www.w3schools.com/tags/att_value.asp

Re: Onclick event

Posted: Wed Apr 17, 2019 7:33 am
by alex4orly
Thanks
Just solved it by changing to "Label" - see here : http://communitylifestyleaccommodation. ... board.html

With this function

<script>
function ShowName()
{
var buttonid = event.srcElement.id;
var buttontext = document.getElementById(buttonid).value;
document.getElementById("Label1").innerHTML = buttontext;
}
</script>

Cheers