Onclick event

This section is for posting questions which are not directly related to WYSIWYG Web Builder.
Examples of off topics: web server configuration, hosting, programming related questions, third party scripts.

Note that these questions will generally not be answered by the administrators of this forum.
Post Reply
User avatar
alex4orly
 
 
Posts: 632
Joined: Mon Jan 20, 2014 8:17 am
Location: Australia
Contact:

Onclick event

Post 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
User avatar
Pablo
 
Posts: 21578
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Onclick event

Post 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
User avatar
alex4orly
 
 
Posts: 632
Joined: Mon Jan 20, 2014 8:17 am
Location: Australia
Contact:

Re: Onclick event

Post 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
Post Reply