PDA

View Full Version : Error on my Function


surferdave
09-03-2002, 11:11 PM
Hello

This function would change the text, color and font depending on mouse over and mouse out.

It works but it creates and JS error everytime.

<SCRIPT LANGUAGE="JavaScript">
function change()
{
txt.innerText="Red Text"
txt.style.color='red'
txt.style.font= '30'
}
function over()
{
txt.innerText="Blue Text"
txt.style.color='blue'
txt.style.font= '30'
}
</script>

<a href="#" onMouseOver="change()" onMouseOut="over()" >Touch me</a>
<p id="txt"></p>

Thanks

Dave

eak
09-03-2002, 11:34 PM
in your functions, they dont know what txt is. you have to tell it. it cant read your mind.

<SCRIPT LANGUAGE="JavaScript">
function change()
{
var txt=document.getElementById('txt');
txt.innerText="Red Text"
txt.style.color='red'
txt.style.font= '30'
}
function over()
{
var txt=document.getElementById('txt');
txt.innerText="Blue Text"
txt.style.color='blue'
txt.style.font= '30'
}
</script>

<a href="#" onMouseOver="change()" onMouseOut="over()" >Touch me</a>
<p id="txt"></p>

surferdave
09-03-2002, 11:44 PM
Thanks eak

But your code create the same error.

I beleive the following two lines of code is creating the problem.
if I remove one of the lines, it works without error.

txt.style.color='red'
txt.style.font= '30'

I think its got something to do with using STYLE twice.

Dave

boywonder
09-03-2002, 11:55 PM
txt.style.fontSize= '30'

style is just a reference to something, you can use it all you want.

surferdave
09-04-2002, 12:30 AM
Thanks boywonder
working great now

:)