I'm trying to rid my code of a couple of eval
s that I have in my javascript, but I'm not sure of the best way to achieve what I'm trying to do.
I have a "filter form" on a bunch of my pages, with a bit of JS attached to it that reloads parts of the page depending on what the user does.
Different pages require different actions though.
So my solution (that I came up with yearrrrs ago...) was
<form name="callback_loadCalendar">
<form name="callback_loadNames">
Etc.
And this horrible bit of JS (attached to onchange events etc) to then call the relevant function:
if (f.getAttribute('name') && f.getAttribute('name').indexOf('callback') === 0)
eval(f.getAttribute('name').substr(9)+'()');
E.g. that would call loadCalendar()
and loadNames()
respectively.
What SHOULD I be doing instead?
Thanks!