Connecting Tech Pros Worldwide Help | Site Map

eval() not working in firefox

Angel
Guest
 
Posts: n/a
#1: Jun 14 '06
Hello Everybody,

I have the following lines in my code

1)
totalElements=eval("document."+formname+".RCBillin gCycle"+totalRCRows+".length")

2) var newoption=new Option (BillingCycleName,BillingCycleId);
eval("document."+formname+".RCBillingCycle"+totalR CRows+".options[totalElements]=
newoption");

In both statements above, the eval code doesnt work in firefox. Is
there a workaround?

Regards,
Angel

Richard Cornford
Guest
 
Posts: n/a
#2: Jun 14 '06

re: eval() not working in firefox


Angel wrote:[color=blue]
> Hello Everybody,
>
> I have the following lines in my code
>
> 1)
> totalElements=eval("document."+formname+".RCBillin gCycle"+totalRCRows+".length")
>
> 2) var newoption=new Option (BillingCycleName,BillingCycleId);
> eval("document."+formname+".RCBillingCycle"+totalR CRows+".options[totalElements]=
> newoption");
>
> In both statements above, the eval code doesnt work in firefox. Is
> there a workaround?[/color]

No workaround is needed as there is no need to use - eval - at all and
it is more likely the shortcut property accessors that is not working
in Firefox.

Replace:-

eval("document."+formname+".RCBillingCycle"+totalR CRows+".length")

-with:-

document.forms[formname].elements['RCBillingCycle'+totalRCRows].length;

- and replace:-

eval("document."+formname+".RCBillingCycle"+totalR CRows+
".options[totalElements]= newoption");

-with:-

document.forms[formname].elements['RCBillingCycle'+
totalRCRows].options[totalElements]= newoption

Richard.

Angel
Guest
 
Posts: n/a
#3: Jun 14 '06

re: eval() not working in firefox


Implemented the code. Got the following error

document.forms[formname].elements['RCBillingCycle'+totalRCRows] has no
properties



Richard Cornford wrote:[color=blue]
> Angel wrote:[color=green]
> > Hello Everybody,
> >
> > I have the following lines in my code
> >
> > 1)
> > totalElements=eval("document."+formname+".RCBillin gCycle"+totalRCRows+".length")
> >
> > 2) var newoption=new Option (BillingCycleName,BillingCycleId);
> > eval("document."+formname+".RCBillingCycle"+totalR CRows+".options[totalElements]=
> > newoption");
> >
> > In both statements above, the eval code doesnt work in firefox. Is
> > there a workaround?[/color]
>
> No workaround is needed as there is no need to use - eval - at all and
> it is more likely the shortcut property accessors that is not working
> in Firefox.
>
> Replace:-
>
> eval("document."+formname+".RCBillingCycle"+totalR CRows+".length")
>
> -with:-
>
> document.forms[formname].elements['RCBillingCycle'+totalRCRows].length;
>
> - and replace:-
>
> eval("document."+formname+".RCBillingCycle"+totalR CRows+
> ".options[totalElements]= newoption");
>
> -with:-
>
> document.forms[formname].elements['RCBillingCycle'+
> totalRCRows].options[totalElements]= newoption
>
> Richard.[/color]

RobG
Guest
 
Posts: n/a
#4: Jun 14 '06

re: eval() not working in firefox


Angel wrote:[color=blue]
> Implemented the code. Got the following error[/color]

Please don't top post here, reply below a trimmed quote.

[color=blue]
> document.forms[formname].elements['RCBillingCycle'+totalRCRows] has no
> properties[/color]

That will return a reference to a form with a name attribute value equal
to the value of - formname - and an element with a name attribute equal
to the value of - 'RCBillingCycle' + totalRCRows -.

e.g.:

<form name="formA" action="">
<input type="text" name="RCBillingCycle0">
</form>

<script type="text/javascript">

var formname = "formA";
var totalRCRows = '0';

// Wrapped for posting
alert(typeof
document.forms[formname].elements['RCBillingCycle'+totalRCRows]
);

</script>

[...]

--
Rob
Matt Kruse
Guest
 
Posts: n/a
#5: Jun 14 '06

re: eval() not working in firefox


Angel wrote:[color=blue]
> I have the following lines in my code
> totalElements=eval("document."+formname+".RCBillin gCycle"+totalRCRows+".length")
> ...[/color]

http://www.JavascriptToolbox.com/bestpractices/#eval

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


Closed Thread


Similar JavaScript / Ajax / DHTML bytes