09-30-2008, 07:15 PM
|
#7 (permalink)
|
|
The Addict
Join Date: Aug 2008
Posts: 336
Thanks: 8
|
in your current for you have a onclick attribute in a input tag, here:
HTML Code:
<input name=\"underline\" onclick=\"
that attribute would make sure that whatever value it has would be run when the element is clicked.
the good practiced is in order to avoid combining scripting with markup we use the onclick event handler in javascript. by just assigning the onclick variable of a element in javascript with code like here
Code:
document.getElementsByName('underline')[0].onclick=function(){
document.getElementsByName('comment')[0].innerHTML = "<u></u>"
};
in there we assigned the function(){...} to the onclick event of the element document.getElementsByName('underline')[0] which is the element <input name="underline" />
that is why we use the onclick in javascript instead of using it in the markup
|
|
|
|