/    Sign up×
Community /Pin to ProfileBookmark

Why doesn’t this work in firefox?

I have this script:

<script language=javascript>
function validate(bigfont){
if (bigfont.checked == 1){
document.all.poemcell.style.fontSize = “22px”;
document.all.titlecell.style.fontSize = “26px”;
document.all.poemtable.style.width= “900”;
}
else{
document.all.poemcell.style.fontSize = “16px”;
document.all.titlecell.style.fontSize = “20px”;

document.all.poemtable.style.width= “700”;
}
}
</script>

and then somewhere in the website I have this part:

<table class=”borderedtable” id=”poemtable”>
<tr>
<td class=”titlecell” id=”titlecell”>{POEMTITLE}</td>
<td class=”titlecell”><input type=”checkbox” name=”bigfont” value=”checkbox” onClick=”return validate(bigfont);”/>Big Font</td>
</tr>
<tr>
<td class=”poemcell” id=”poemcell”>{POEMBODY}</td>
<td class=”coverimg”><img src=”images/cover.jpg”></td>
</tr>
<tr>
</tr>

</table>

in IE everything works, the table and font size are increased/decreased when the box is checked/unchecked but in firefox nothing happens, what am I doing wrong?

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterMay 24.2006 — Change document.all.poemcell.style to

document.getElementById("poemcell").style

etc, etc.
Copy linkTweet thisAlerts:
@IcelineauthorMay 24.2006 — thanks, it still does nothing in firefox though, is onClick="return validate(bigfont);" incorrect?
Copy linkTweet thisAlerts:
@KorMay 24.2006 — if ([B]bigfont.checked[/B]){

return validate([B]this[/B])
Copy linkTweet thisAlerts:
@KorMay 24.2006 — thanks, it still does nothing in firefox though, is onClick="return validate(bigfont);" incorrect?[/QUOTE]

Yes, it is incorrect. IE silly can refere the object even without any root (document). It this case u mai use [B]this[/B] as self reference.
Copy linkTweet thisAlerts:
@IcelineauthorMay 24.2006 — sorry, I'm still very new to js, how will I use what you just said? could you alter my script so it works? I'm probably doing it wrong from the start, what I want is that when the checkbox 'bigfont' is checked it changes:

poemcell fontsize to 22px

titlecell fontsize to 26px

poemtable width to 900px

and when it's unchecked they should be restored to their original measures:

poemcell fontsize to 16px

titlecell fontsize to 20px

poemtable width to 700px
Copy linkTweet thisAlerts:
@KorMay 24.2006 — if ([B]bigfont.checked[/B]){

....

document.getElementById('poemtable').style.width= "900[B]px[/B]";

document.getElementById('poemtable').style.width= "700[B]px[/B]";

......

onclick="validate([B]this[/B])"

see the bolded? these are the changes (and, of course, all the elements should be refered by id as well)
------


You don't need the [I]return[/I] conditioner
Copy linkTweet thisAlerts:
@IcelineauthorMay 24.2006 — EDIT: Nevermind

Thanks, it works now, finally ?
Copy linkTweet thisAlerts:
@IcelineauthorMay 25.2006 — Hey, another thing that works in IE but doesn't work in ff is this:

<tr>

<td bgcolor="#0066FF" id="Row1">Itemname</td>

<td align="center" bgcolor="#FF0000"><input type="radio" name="Row1Group" value="1" onClick="Row1.style.backgroundColor='#FF0000'"></td>

<td align="center" bgcolor="#0066FF"><input type="radio" name="Row1Group" value="2" checked onClick="Row1.style.backgroundColor='#0066FF'"></td>

<td align="center" bgcolor="#00CC33"><input type="radio" name="Row1Group" value="3" onClick="Row1.style.backgroundColor='#00CC33'"></td>

</tr>

I tried using document.getElementById("Row1") instead of just Row1, but that causes it to neither work in IE nor ff, is this possible in ff without using functions?
Copy linkTweet thisAlerts:
@KorMay 25.2006 — 

I tried using document.getElementById("Row1") instead of just Row1, but that causes it to neither work in IE nor ff, is this possible in ff without using functions?[/QUOTE]


Are u sure u have try? Should work by all means and it works for me in both browsers. Check if you have a single element with id="Row1". Id must be unique. and use single quotes, not double to mark the string id.

[code=php]
<table>
<tr>
<td bgcolor="#0066FF" id="Row1">Itemname</td>
<td align="center" bgcolor="#FF0000"><input type="radio" name="Row1Group" value="1" onClick="document.getElementById('Row1').style.backgroundColor='#FF0000'"></td>
<td align="center" bgcolor="#0066FF"><input type="radio" name="Row1Group" value="2" checked onClick="document.getElementById('Row1').style.backgroundColor='#0066FF'"></td>
<td align="center" bgcolor="#00CC33"><input type="radio" name="Row1Group" value="3" onClick="document.getElementById('Row1').style.backgroundColor='#00CC33'"></td>
</tr>
</table>
[/code]
Copy linkTweet thisAlerts:
@IcelineauthorMay 25.2006 — hm, when I test this as a seperate fil it does work, so I guess there is an error in another part of the file somewhere, I do us unique ID's though, odd, I'll just try and figure it out, thanks though!

EDIT:

I found it, it didn't work in ff because I had a bgcolor set in the html file.
×

Success!

Help @Iceline spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...