0
Thanks

A few words of thanks would be greatly appreciated.

JavaScript code to display text in a defined area upon click



Issue


I am looking for a JavaScript code that would allow me to display text in a defined area when I click on a link.

The page in question is composed of blocks set via CSS.

In the <head> tag:
<SCRIPT LANGUAGE="JavaScript">
function ChangeMessage(message,champ)
  {
  if(document.getElementById)
    document.getElementById(champ).innerHTML = message;
  }
</SCRIPT>



and in <body> :
<A HREF="page.htm" onMouseOver="ChangeMessage('Texte','ejs_texte')" onMouseOut="ChangeMessage('','ejs_texte')">Lien</A>
.

Solution


To trigger action upon click, you must change the HTML event:
<a href="page.htm" onclick="ChangeMessage('Texte','ejs_texte')" >Lien</a>
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled « JavaScript code to display text in a defined area upon click », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!