/    Sign up×
Community /Pin to ProfileBookmark

Javascript NOT working in Firefox but works in IE

Ok, I did my research and I tried various solutions to no avail.

I have little or no knowledge of JSP and this internship required me to troubleshoot this Javascript bug.

Implementation : It is a simple select all implementation. When the parent checkbox is toggled, all the child elements are toggled as well.

Any help is highly appreciated. Thank you.

This is the actual Javascript code :

[CODE]
function Commodity(oThis) {
var p=0;
if (this.document.searchform.Commodity!= null) {
for(p=0; p<this.document.searchform.Commodity.length;p++) {
if (this.document.searchform.Commodity[p].value == oThis.value) {
this.document.searchform.Commodity[p].checked = oThis.checked;
break;
}
}
}

for (var i = 0; i < this.document.searchform.Engine.length; i++) {
if(this.document.getElementById(this.document.searchform.Engine[i].value) == null) {
if (this.document.searchform.Engine[i].key == oThis.value) {
if (this.document.searchform.Commodity[p].checked){
this.document.searchform.Engine[i].checked = true;
this.document.searchform.Engine[i].disabled = true;
} else {
this.document.searchform.Engine[i].checked = false;
this.document.searchform.Engine[i].disabled = false;
}
}
}
}
}

function Supplier(oThis) {
if (this.document.searchform.Engine.length != null) {
for (var i = 0; i < this.document.searchform.Engine.length; i++) {
if (this.document.searchform.Engine[i].value == oThis.value &&
this.document.searchform.Engine[i].key == oThis.key) {
this.document.searchform.Engine[i].checked = oThis.checked;
break;
}
}
} else {
if (this.document.searchform.Engine.value == oThis.value &&
this.document.searchform.Engine.key == oThis.key) {
this.document.searchform.Engine.checked = oThis.checked;
}
}
}
[/CODE]

This is the search.do code (HTML below)

[CODE]
<div id=”m_1″ class=”modbox” portletid=”3″ style=”left: 0px; top: 0px;”>
<div class=”modtitle”>
<h2 id=”m_1_link” class=”lnk”>
<input type=”checkbox” title=”” onclick=”Commodity(this)” value=”3″ name=”Commodity”/>
<span id=”m_1_title” class=”modtitle_text” title=”Test One” style=”cursor: pointer;”> Test One</span>
</h2>
<a id=”m_1_zippy” class=”minbox” title=”Minimize” href=”#” onclick=”chgTT(this);return _zm(‘1’);return false;”/>
<div id=”m_1_h” class=”dt” title=”Test One” style=”cursor: move;”/>
</div>
<div id=”m_1_b” class=”modboxin”>
<input type=”checkbox” key=”3″ value=”4″ name=”Engine” onclick=”javascript:Supplier(this)”/>
<span>Grainger</span>
<br/>
<input type=”checkbox” key=”3″ value=”472″ name=”Engine” onclick=”javascript:Supplier(this)”/>
<span>Local Catalog1</span>
<br/>
<input type=”checkbox” key=”3″ value=”477″ name=”Engine” onclick=”javascript:Supplier(this)”/>
<span>Local Catalog6</span>
<br/>
<input type=”checkbox” key=”3″ value=”478″ name=”Engine” onclick=”javascript:Supplier(this)”/>
<span>Local Catalog7</span>
<br/>
<input type=”checkbox” disabled=”disabled”/>
<span>
</span>
<br/>
</div>
[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@FangMar 16.2009 — Why are you using the keyword [I]this[/I]?

The anchor wrapping the form is invalid; an inline element can not contain block elements.

The pseudo protocol [I]javascript:[/I] is unnecessary.

Using proprietary attributes can cause referencing problems.
Copy linkTweet thisAlerts:
@rayofvictoryauthorMar 16.2009 — Hi Fang, thanks for the quick reply.

That is the previous developer's code, I am asked to troubleshoot.

Interestingly it works in IE, hence the confusion.

I have no idea on jsp, it is adding to the problem ?

Took javascript: off as suggested, no go.

anchor wrapping the form is invalid : May I know more about this statement?

Thank you.
Copy linkTweet thisAlerts:
@FangMar 16.2009 — Try removing [B]this.[/B] from the functions.

The anchor is incorrectly closed. How this affects the script is pure guesswork.

Which is the parent checkbox?

A link would be more useful; this snippet does not function at all.
×

Success!

Help @rayofvictory 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 4.26,
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,
)...