soeren wrote:
Sometimes one needs to assemble the Javascript by PHPright in the component's PHP file. Then you can't outsource the JS code easily into an external file. What to do then?
One of the ways I got around this problem was by dynamically building for loops, then eval'ing the results at template generation time.
Take a look at this:
http://j2.jomres.net/ & click on the link to the component (I aint saying which one cos I'll get accused of self promotion
Just check my sig. )
If you visit the booking form via the Book a room link the optional extras and address panel are hidden divs before anything is clicked, however if you go to it via clicking a room's availability calendar the panels are un-hidden. This is done by creating an array of the hidediv("yadda") then eval'ing those at template generation time, depending on prior conditions:
This is in the actual template file:
Code: Select all
var x
var toload=new Array()
<patTemplate:tmpl name="onload">toload[{COUNT}]= "{ONLOAD}" </patTemplate:tmpl>
And from the linked to javascript file:
Code: Select all
//onload function
function generic()
{
for (x in toload)
{
eval(toload[x]);
}
}
Of course, this isn't exactly what you're asking for, but maybe it'll help. My point is that it might be possible to have the required javascript permanently built into your linked to javascript file and simply define a set of triggers that are built at compile time of the template, eg if this user is not an administrator, checkThisInput = true, then onclick=validate(checkThisInput) and in the function if checkThisInput is true actually do the validation. It might sound long winded, but it works.
By the tone of your last post you sound tired and frustrated. Maybe you just need to leave it alone for a few days, come back when you're less fed up with it?
Just trying to help, good luck.