Javascript code not running in FIREFOX

C

Coder

Hi I have the following code in java script, it is not giving proper
output in FIREFOX but running fine in IE... can anybody help me out to
make this run in FIREFOX .


<script language="JavaScript">
var cntlName;
var eleTarget = document.getElementById('hiding');

function showOrHide(){
alert ("hi");
var eleSource = event.srcElement;

if (event.srcElement) {
//for IE
var eleSource = event.srcElement;
}
else {
//for Firefox
var eleSource = event.target;
}

if (eleSource.value == 'MGRPAY') {
//for IE
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}

for(var i=0; i<preProcessControlArray.length; i++){
cntlName = eval(preProcessControlArray);
if (cntlName.m_oSubmit.name.toLowerCase() == 'p_par_rad_role'){
if (cntlName.m_oForm.length) {
for( var j=0; j<cntlName.m_oForm.length; j++ ){
if (j == 0) {
cntlName.m_oForm[j].focus();
cntlName.m_oForm[j].click();
if (cntlName.m_oForm[j].value == 'MGRPAY') {
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}
//For IE
if(cntlName.m_oForm[j].attachEvent)
cntlName.m_oForm[j].attachEvent('onpropertychange',
showOrHide);
//for firefox
else
cntlName.m_oForm[j].addEventListener('onchange',
showOrHide,false);
}
}
else {
cntlName.m_oForm.focus();
cntlName.m_oForm.click();
if (cntlName.m_oForm.value == 'MGRPAY') {
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}
}
}
</script>
 
S

sowencheung

i don't know what error u r encountering
did u install FireBug to debug ur js in FF?

i think u will have better feedback with that tool
 
C

Coder

I am using this java script code to show and hide a prompt box in
Cognos reportnet , it is working fine in IE , but when it comes to
Firefox then it does not becomes activated . Even if I click any button
in same prompt , the next prompt does not show up.

It is not returning any error to me but its simply not working.So if
the code can be modified so that it works fine with Firefox.

i don't know what error u r encountering
did u install FireBug to debug ur js in FF?

i think u will have better feedback with that tool

Hi I have the following code in java script, it is not giving proper
output in FIREFOX but running fine in IE... can anybody help me out to
make this run in FIREFOX .


<script language="JavaScript">
var cntlName;
var eleTarget = document.getElementById('hiding');

function showOrHide(){
alert ("hi");
var eleSource = event.srcElement;

if (event.srcElement) {
//for IE
var eleSource = event.srcElement;
}
else {
//for Firefox
var eleSource = event.target;
}

if (eleSource.value == 'MGRPAY') {
//for IE
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}

for(var i=0; i<preProcessControlArray.length; i++){
cntlName = eval(preProcessControlArray);
if (cntlName.m_oSubmit.name.toLowerCase() == 'p_par_rad_role'){
if (cntlName.m_oForm.length) {
for( var j=0; j<cntlName.m_oForm.length; j++ ){
if (j == 0) {
cntlName.m_oForm[j].focus();
cntlName.m_oForm[j].click();
if (cntlName.m_oForm[j].value == 'MGRPAY') {
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}
//For IE
if(cntlName.m_oForm[j].attachEvent)
cntlName.m_oForm[j].attachEvent('onpropertychange',
showOrHide);
//for firefox
else
cntlName.m_oForm[j].addEventListener('onchange',
showOrHide,false);
}
}
else {
cntlName.m_oForm.focus();
cntlName.m_oForm.click();
if (cntlName.m_oForm.value == 'MGRPAY') {
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}
}
}
</script>
 
R

Richard Cornford

Coder said:
Hi I have the following code in java script, it is not giving
proper output in FIREFOX but running fine in IE... can anybody
help me out to make this run in FIREFOX .

<script language="JavaScript">
var cntlName;
var eleTarget = document.getElementById('hiding');

function showOrHide(){
alert ("hi");
var eleSource = event.srcElement;
^^^^^
Firefox/Mozilla/Gecko browsers do not use an global - event - property,
instead passing event objects as the argument to the event handling
function. Because the - event - Identifier does not refer to a defined
property of the global object it evaluates as the undefined value, and
the subsequent attempt to read the - srcElement - property of an
undefined value will have firefox error-out.Firefox/Mozilla/Gecko
browsers do not use an global - event - property, instead passing event
objects as the argument to the event handling function. Because the -
event - Identifier does not refer to a defined property of the global
object it evaluates as the undefined value, and the subsequent attempt
to read the - srcElement - property of an undefined value will have
firefox error-out.
if (event.srcElement) {
//for IE
var eleSource = event.srcElement;
}
else {
//for Firefox
var eleSource = event.target;
}

if (eleSource.value == 'MGRPAY') {
//for IE
eleTarget.style.display = 'block';

If - eleSource - is an input element, as the use of its value property
may imply, then its default CSS display style is 'inline' not 'block'.
}
else {
eleTarget.style.display = 'none';
}
}

function showOrHide(ev){
var eleSource;
ev = ev || window.event;
if(eleSource = (ev.srcElement||ev.target)){
if(eleSource.value == 'MGRPAY'){
eleTarget.style.display = '';
}else{
eleTarget.style.display = 'none';
}
}
}
for(var i=0; i<preProcessControlArray.length; i++){
cntlName = eval(preProcessControlArray);


The contents of - preProcessControlArray - are not shown here so what
this code does, or may be intended to do, is unknown. Though generally
any use of - eval - is indicative of failing to do something else what
would be objectively better.

However, if this array contains control names in the form of string
then - eval -ing them will be equivalent to resolving Identifiers as
properties on the scope chain, or more likely the global object. IE
makes (at least some) named elements into properties of the global
object that refer to the elements. Firefox/Mozilla/Gecko browsers do not
tend to do this.
if (cntlName.m_oSubmit.name.toLowerCase() == 'p_par_rad_role'){
if (cntlName.m_oForm.length) {
for( var j=0; j<cntlName.m_oForm.length; j++ ){
if (j == 0) {
cntlName.m_oForm[j].focus();
cntlName.m_oForm[j].click();
if (cntlName.m_oForm[j].value == 'MGRPAY') {
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}
//For IE
if(cntlName.m_oForm[j].attachEvent)
cntlName.m_oForm[j].attachEvent('onpropertychange',
showOrHide);
//for firefox
else
cntlName.m_oForm[j].addEventListener('onchange',
<snip> ^^^^^^^^
The addEventListener method takes the event name as its argument not the
name of the intrinsic event property, so here it would be 'change'
rather than 'onchange'.

The onchange hander is not triggered under equivalent conditions to the
onpropertychange even in IE, and IE does support onchange.

Richard.
 
C

Coder

I have changed that part to 'change' but it is still not working there
is some issue with the showOrHide part which I am unable to figure out
....because in Firefox the alert ("hi 2"); is not coming up and that is
the code for showOrHide

<script language="JavaScript">
var cntlName;
var eleTarget = document.getElementById('hiding');

function showOrHide(){

var eleSource = event.srcElement;


if (event.srcElement) {
//for IE
alert ("hi 1");
var eleSource = event.srcElement;
}
else {
//for Firefox
alert ("hi 2");
var eleSource = event.target;
}

if (eleSource.value == 'MGRPAY') {
//for IE
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}

for(var i=0; i<preProcessControlArray.length; i++){
cntlName = eval(preProcessControlArray);
if (cntlName.m_oSubmit.name.toLowerCase() == 'p_par_rad_role'){
if (cntlName.m_oForm.length) {
for( var j=0; j<cntlName.m_oForm.length; j++ ){
if (j == 0) {
cntlName.m_oForm[j].focus();
cntlName.m_oForm[j].click();
if (cntlName.m_oForm[j].value == 'MGRPAY') {
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}
//For IE
if(cntlName.m_oForm[j].attachEvent)
cntlName.m_oForm[j].attachEvent('onpropertychange',
showOrHide);
//for firefox
cntlName.m_oForm[j].addEventListener('change',showOrHide,false);
}
}
else {
cntlName.m_oForm.focus();
cntlName.m_oForm.click();
if (cntlName.m_oForm.value == 'MGRPAY') {
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}
}
}
</script>

Richard said:
Coder said:
Hi I have the following code in java script, it is not giving
proper output in FIREFOX but running fine in IE... can anybody
help me out to make this run in FIREFOX .

<script language="JavaScript">
var cntlName;
var eleTarget = document.getElementById('hiding');

function showOrHide(){
alert ("hi");
var eleSource = event.srcElement;
^^^^^
Firefox/Mozilla/Gecko browsers do not use an global - event - property,
instead passing event objects as the argument to the event handling
function. Because the - event - Identifier does not refer to a defined
property of the global object it evaluates as the undefined value, and
the subsequent attempt to read the - srcElement - property of an
undefined value will have firefox error-out.Firefox/Mozilla/Gecko
browsers do not use an global - event - property, instead passing event
objects as the argument to the event handling function. Because the -
event - Identifier does not refer to a defined property of the global
object it evaluates as the undefined value, and the subsequent attempt
to read the - srcElement - property of an undefined value will have
firefox error-out.
if (event.srcElement) {
//for IE
var eleSource = event.srcElement;
}
else {
//for Firefox
var eleSource = event.target;
}

if (eleSource.value == 'MGRPAY') {
//for IE
eleTarget.style.display = 'block';

If - eleSource - is an input element, as the use of its value property
may imply, then its default CSS display style is 'inline' not 'block'.
}
else {
eleTarget.style.display = 'none';
}
}

function showOrHide(ev){
var eleSource;
ev = ev || window.event;
if(eleSource = (ev.srcElement||ev.target)){
if(eleSource.value == 'MGRPAY'){
eleTarget.style.display = '';
}else{
eleTarget.style.display = 'none';
}
}
}
for(var i=0; i<preProcessControlArray.length; i++){
cntlName = eval(preProcessControlArray);


The contents of - preProcessControlArray - are not shown here so what
this code does, or may be intended to do, is unknown. Though generally
any use of - eval - is indicative of failing to do something else what
would be objectively better.

However, if this array contains control names in the form of string
then - eval -ing them will be equivalent to resolving Identifiers as
properties on the scope chain, or more likely the global object. IE
makes (at least some) named elements into properties of the global
object that refer to the elements. Firefox/Mozilla/Gecko browsers do not
tend to do this.
if (cntlName.m_oSubmit.name.toLowerCase() == 'p_par_rad_role'){
if (cntlName.m_oForm.length) {
for( var j=0; j<cntlName.m_oForm.length; j++ ){
if (j == 0) {
cntlName.m_oForm[j].focus();
cntlName.m_oForm[j].click();
if (cntlName.m_oForm[j].value == 'MGRPAY') {
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}
//For IE
if(cntlName.m_oForm[j].attachEvent)
cntlName.m_oForm[j].attachEvent('onpropertychange',
showOrHide);
//for firefox
else
cntlName.m_oForm[j].addEventListener('onchange',
<snip> ^^^^^^^^
The addEventListener method takes the event name as its argument not the
name of the intrinsic event property, so here it would be 'change'
rather than 'onchange'.

The onchange hander is not triggered under equivalent conditions to the
onpropertychange even in IE, and IE does support onchange.

Richard.
 
C

Coder

I have changed that part to 'change' but it is still not working there
is some issue with the showOrHide part which I am unable to figure out
....because in Firefox the alert ("hi 2"); is not coming up and that is
the code for showOrHide

<script language="JavaScript">
var cntlName;
var eleTarget = document.getElementById('hiding');

function showOrHide(){

var eleSource = event.srcElement;


if (event.srcElement) {
//for IE
alert ("hi 1");
var eleSource = event.srcElement;
}
else {
//for Firefox
alert ("hi 2");
var eleSource = event.target;
}

if (eleSource.value == 'MGRPAY') {
//for IE
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}

for(var i=0; i<preProcessControlArray.length; i++){
cntlName = eval(preProcessControlArray);
if (cntlName.m_oSubmit.name.toLowerCase() == 'p_par_rad_role'){
if (cntlName.m_oForm.length) {
for( var j=0; j<cntlName.m_oForm.length; j++ ){
if (j == 0) {
cntlName.m_oForm[j].focus();
cntlName.m_oForm[j].click();
if (cntlName.m_oForm[j].value == 'MGRPAY') {
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}
//For IE
if(cntlName.m_oForm[j].attachEvent)
cntlName.m_oForm[j].attachEvent('onpropertychange',
showOrHide);
//for firefox
cntlName.m_oForm[j].addEventListener('change',showOrHide,false);
}
}
else {
cntlName.m_oForm.focus();
cntlName.m_oForm.click();
if (cntlName.m_oForm.value == 'MGRPAY') {
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}
}
}
</script>

Richard said:
Coder said:
Hi I have the following code in java script, it is not giving
proper output in FIREFOX but running fine in IE... can anybody
help me out to make this run in FIREFOX .

<script language="JavaScript">
var cntlName;
var eleTarget = document.getElementById('hiding');

function showOrHide(){
alert ("hi");
var eleSource = event.srcElement;
^^^^^
Firefox/Mozilla/Gecko browsers do not use an global - event - property,
instead passing event objects as the argument to the event handling
function. Because the - event - Identifier does not refer to a defined
property of the global object it evaluates as the undefined value, and
the subsequent attempt to read the - srcElement - property of an
undefined value will have firefox error-out.Firefox/Mozilla/Gecko
browsers do not use an global - event - property, instead passing event
objects as the argument to the event handling function. Because the -
event - Identifier does not refer to a defined property of the global
object it evaluates as the undefined value, and the subsequent attempt
to read the - srcElement - property of an undefined value will have
firefox error-out.
if (event.srcElement) {
//for IE
var eleSource = event.srcElement;
}
else {
//for Firefox
var eleSource = event.target;
}

if (eleSource.value == 'MGRPAY') {
//for IE
eleTarget.style.display = 'block';

If - eleSource - is an input element, as the use of its value property
may imply, then its default CSS display style is 'inline' not 'block'.
}
else {
eleTarget.style.display = 'none';
}
}

function showOrHide(ev){
var eleSource;
ev = ev || window.event;
if(eleSource = (ev.srcElement||ev.target)){
if(eleSource.value == 'MGRPAY'){
eleTarget.style.display = '';
}else{
eleTarget.style.display = 'none';
}
}
}
for(var i=0; i<preProcessControlArray.length; i++){
cntlName = eval(preProcessControlArray);


The contents of - preProcessControlArray - are not shown here so what
this code does, or may be intended to do, is unknown. Though generally
any use of - eval - is indicative of failing to do something else what
would be objectively better.

However, if this array contains control names in the form of string
then - eval -ing them will be equivalent to resolving Identifiers as
properties on the scope chain, or more likely the global object. IE
makes (at least some) named elements into properties of the global
object that refer to the elements. Firefox/Mozilla/Gecko browsers do not
tend to do this.
if (cntlName.m_oSubmit.name.toLowerCase() == 'p_par_rad_role'){
if (cntlName.m_oForm.length) {
for( var j=0; j<cntlName.m_oForm.length; j++ ){
if (j == 0) {
cntlName.m_oForm[j].focus();
cntlName.m_oForm[j].click();
if (cntlName.m_oForm[j].value == 'MGRPAY') {
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}
//For IE
if(cntlName.m_oForm[j].attachEvent)
cntlName.m_oForm[j].attachEvent('onpropertychange',
showOrHide);
//for firefox
else
cntlName.m_oForm[j].addEventListener('onchange',
<snip> ^^^^^^^^
The addEventListener method takes the event name as its argument not the
name of the intrinsic event property, so here it would be 'change'
rather than 'onchange'.

The onchange hander is not triggered under equivalent conditions to the
onpropertychange even in IE, and IE does support onchange.

Richard.
 
C

Coder

I have changed that part to 'change' but it is still not working there
is some issue with the showOrHide part which I am unable to figure out
....because in Firefox the alert ("hi 2"); is not coming up and that is
the code for showOrHide

<script language="JavaScript">
var cntlName;
var eleTarget = document.getElementById('hiding');

function showOrHide(){

var eleSource = event.srcElement;


if (event.srcElement) {
//for IE
alert ("hi 1");
var eleSource = event.srcElement;
}
else {
//for Firefox
alert ("hi 2");
var eleSource = event.target;
}

if (eleSource.value == 'MGRPAY') {
//for IE
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}

for(var i=0; i<preProcessControlArray.length; i++){
cntlName = eval(preProcessControlArray);
if (cntlName.m_oSubmit.name.toLowerCase() == 'p_par_rad_role'){
if (cntlName.m_oForm.length) {
for( var j=0; j<cntlName.m_oForm.length; j++ ){
if (j == 0) {
cntlName.m_oForm[j].focus();
cntlName.m_oForm[j].click();
if (cntlName.m_oForm[j].value == 'MGRPAY') {
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}
//For IE
if(cntlName.m_oForm[j].attachEvent)
cntlName.m_oForm[j].attachEvent('onpropertychange',
showOrHide);
//for firefox
cntlName.m_oForm[j].addEventListener('change',showOrHide,false);
}
}
else {
cntlName.m_oForm.focus();
cntlName.m_oForm.click();
if (cntlName.m_oForm.value == 'MGRPAY') {
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}
}
}
</script>

Richard said:
Coder said:
Hi I have the following code in java script, it is not giving
proper output in FIREFOX but running fine in IE... can anybody
help me out to make this run in FIREFOX .

<script language="JavaScript">
var cntlName;
var eleTarget = document.getElementById('hiding');

function showOrHide(){
alert ("hi");
var eleSource = event.srcElement;
^^^^^
Firefox/Mozilla/Gecko browsers do not use an global - event - property,
instead passing event objects as the argument to the event handling
function. Because the - event - Identifier does not refer to a defined
property of the global object it evaluates as the undefined value, and
the subsequent attempt to read the - srcElement - property of an
undefined value will have firefox error-out.Firefox/Mozilla/Gecko
browsers do not use an global - event - property, instead passing event
objects as the argument to the event handling function. Because the -
event - Identifier does not refer to a defined property of the global
object it evaluates as the undefined value, and the subsequent attempt
to read the - srcElement - property of an undefined value will have
firefox error-out.
if (event.srcElement) {
//for IE
var eleSource = event.srcElement;
}
else {
//for Firefox
var eleSource = event.target;
}

if (eleSource.value == 'MGRPAY') {
//for IE
eleTarget.style.display = 'block';

If - eleSource - is an input element, as the use of its value property
may imply, then its default CSS display style is 'inline' not 'block'.
}
else {
eleTarget.style.display = 'none';
}
}

function showOrHide(ev){
var eleSource;
ev = ev || window.event;
if(eleSource = (ev.srcElement||ev.target)){
if(eleSource.value == 'MGRPAY'){
eleTarget.style.display = '';
}else{
eleTarget.style.display = 'none';
}
}
}
for(var i=0; i<preProcessControlArray.length; i++){
cntlName = eval(preProcessControlArray);


The contents of - preProcessControlArray - are not shown here so what
this code does, or may be intended to do, is unknown. Though generally
any use of - eval - is indicative of failing to do something else what
would be objectively better.

However, if this array contains control names in the form of string
then - eval -ing them will be equivalent to resolving Identifiers as
properties on the scope chain, or more likely the global object. IE
makes (at least some) named elements into properties of the global
object that refer to the elements. Firefox/Mozilla/Gecko browsers do not
tend to do this.
if (cntlName.m_oSubmit.name.toLowerCase() == 'p_par_rad_role'){
if (cntlName.m_oForm.length) {
for( var j=0; j<cntlName.m_oForm.length; j++ ){
if (j == 0) {
cntlName.m_oForm[j].focus();
cntlName.m_oForm[j].click();
if (cntlName.m_oForm[j].value == 'MGRPAY') {
eleTarget.style.display = 'block';
}
else {
eleTarget.style.display = 'none';
}
}
//For IE
if(cntlName.m_oForm[j].attachEvent)
cntlName.m_oForm[j].attachEvent('onpropertychange',
showOrHide);
//for firefox
else
cntlName.m_oForm[j].addEventListener('onchange',
<snip> ^^^^^^^^
The addEventListener method takes the event name as its argument not the
name of the intrinsic event property, so here it would be 'change'
rather than 'onchange'.

The onchange hander is not triggered under equivalent conditions to the
onpropertychange even in IE, and IE does support onchange.

Richard.
 
T

The Magpie

Coder said:
I have changed that part to 'change' but it is still not working there
is some issue with the showOrHide part which I am unable to figure out
....because in Firefox the alert ("hi 2"); is not coming up and that is
the code for showOrHide
Well, part of the problem is that you are still trying to use a global
"event" property which, as was mentioned, Firefox does not have.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top