...

View Full Version : JS Function - Change innerHTML Help



eimpact
07-08-2012, 10:01 PM
Why won't the following work?

<script type="text/javascript">
function changePrac(){
document.getElementById('pracDesc').innerHTML ='test';
document.prac.src='/uploads/pracs/test.jpg';
}
</script>

If I take out the line that is trying to change the innerHTML it works, as shown below, but I need it to work as show above...

<script type="text/javascript">
function changePrac(){
document.prac.src='/uploads/pracs/test.jpg';
}
</script>

felgall
07-08-2012, 10:06 PM
What does the HTML that is referencing look like?

eimpact
07-08-2012, 10:12 PM
<a href="#" onmouseover="changePrac(); return false;">test</a>

felgall
07-08-2012, 10:39 PM
That HTML doesn't contain anything for the document.getElementById('pracDesc').i and document.prac to reference and so if that is all the HTML you have then the function can do nothing.

eimpact
07-08-2012, 11:19 PM
Oh...you're looking for this:

<div id="pracDesc">

eimpact
07-09-2012, 01:58 AM
If it helps, here is the page with the code:

http://dev.curbing.net/Practitioners/

Sing
07-09-2012, 02:46 AM
<script type="text/javascript">
function changePrac(){
document.getElementById("pracDesc").innerHTML = "test";
document.prac.src = "/uploads/pracs/test.jpg";
}
</script>


Couple extra suggestions -
1. Why use a href when it could just as easily be a span for them to mouse over? You already styled it, so they'll know it's hoverable. Unless of you eventually plan on taking them to a page, then ignore this.

2. May I suggest using just one changePrac function and sending parameters to it, instead of a new function for each?

If you wanted to try using parameters, it would look like this

<script type="text/javascript">
function changePrac(name, image){
document.getElementById("pracDesc").innerHTML = name;
document.prac.src = "/uploads/pracs/" + image;
}
</script>

<span style="color:#9CCCE3; font-size:9pt; font-weight:bolder; font-family:Helvetica Neue, Helvetica, Arial, sans-serif; letter-spacing:1px"
onmouseover="changePrac('Fred Flinstone', 'test.jpg');">
MOUSE OVER ME</span>

eimpact
07-09-2012, 06:04 AM
I don't get it...not working. Check it out at http://dev.curbing.net/Services/.

eimpact
07-09-2012, 06:15 AM
OK...got Services page working, but still can't figure out what is wrong with this page:

http://dev.curbing.net/Practitioners/

eimpact
07-09-2012, 07:46 PM
Any thoughts?

xelawho
07-09-2012, 08:38 PM
try the error console - it's fairly plain what the problem is



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum