Friday, April 10, 2009

Allowing Users to Change attribute of the HTML tag using javascript


Normally we will set values for attributes of HTML tag during design time.

But each user will be expecting different values. For example "scrollamount='2'" set in marquee tag may not be suitable for all users. Some people will expect more speed of scrolling and some other will expect slow movement.

So it is better to allow the user to set their own value. Find below the example code (javascript) which will allow the user to increase scrolling speed by clicking on the marquee text. Double clicking on the text will reset the value.
You can experience it using the quote displaying on top of our blog. Currently it is working on FireFox only, it is not working in IE (internet explorer).


<marquee id="quote" scrollamount="2" onDblClick="resetvalue(this);" scrolldelay="0"
onClick="changevalue(this);">scrolling text will come here... </marquee>


<script language="javascript">
function changevalue(marqTag)
{
newvalue=parseInt(marqTag.getAttribute("scrollamount"))+1;
marqTag.setAttribute("scrollamount",newvalue);


}
function resetvalue(marqTag)
{
marqTag.setAttribute("scrollamount","1");

}
<script>


More Articles...

No comments:

Search This Blog