Thanks Tobie, that has made a big difference.
On Jan 16, 10:57 am, Tobie Langel <[EMAIL PROTECTED]> wrote:
> Hi Gareth,
>
> You shouldn't be using eval for this.
>
> There are very few legitimate uses of the eval construct.
>
> This is certainly not one of them.
>
> You should be using the following instead:
>
> foo[bar] // GOOD
> eval(foo + '.' + bar) // AWFUL!
>
> Try the following:
>
> var widgetId = "ST_1";
> var widgetStyleParam = "border";
> var widgetStyleValue = "1px solid black";
> $(widgetId).style[widgetStyleParam] =
> widgetStyleValue;
>
> Note that you'd probably be better of using Element#setStyle like so:
>
> $(widgetId).setStyle('border: 1px solid black;');
>
> Hope this helps,
>
> Tobie
>
> On Jan 16, 11:34 am, GarethAtFlignet <[EMAIL PROTECTED]>
> wrote:
>
> > HI there,
>
> > here is a basic piece of HTML/JavaScript that duplicates something
> > similar in an application we're working on:
>
> > <html>
> > <head>
> > <script src="prototype.js" type="text/javascript" ></script>
> > </head>
>
> > <body>
> > <div id="ST_1">ST_1</div>
> > </body>
>
> > <script>
> > var widgetId = "ST_1";
> > var widgetStyleParam = "border";
> > var widgetStyleValue = "1px solid black";
> >
> > eval("$("+widgetId+").style."+widgetStyleParam+"='"+widgetStyleValue
> > +"'");
> > </script>
> > </html>
>
> > The problem we're having is that with firebug enabled the eval line
> > raises the following warning in Firebug:
>
> > "Element referenced by ID/NAME in the global scope. Use W3C standard
> > document.getElementById() instead."
>
> > as we make 'lots' of use of the above type of eval statement (and have
> > a large number of page elements) the performance hit makes some of our
> > subsecond loops take tens of seconds. No performance hit if firebug is
> > turned off though.
>
> > I've read in some other posts something about the warning being
> > incorrect and that prototype is working as intended, but that doesn't
> > help with the first impressions people get when running our app if
> > firebug is installed and enabled (which is quite common amongst
> > developers).
>
> > I'm sure there is something obvious we've overlooked and any help is
> > appreciated.
>
> > Many thanks again,
>
> > Gareth
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---