Write is as: private String alert = "document.jsAlert = function () { alert(\"HELLO\"); }";
Because tapestry includes such initialization in Tapestry.onDOMLoaded( ... ) the scope of jsAlert (in your original version) is not the current document but an anonymous function - and it is lost after the function exits. So, just attach it to the document and it'll be there when you call it. On Wed, Nov 26, 2008 at 1:24 PM, Lance White <[EMAIL PROTECTED]> wrote: > > Hi, > > I'm trying to embed some JavaScript in a component, and for the life of me > cannot get it to work. I can sort of understand why it's not working, I just > can't see what to do to fix it - if anyone can point me towards a > resolution, I'd be grateful - I'm currently playing with 5.0.15. > > OK, this isn't my actual component, but it shows the problem... a simple > component that has a button that calls a javascript function. > > TML > ---- > <div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"> > <input type="button" onclick="jsAlert()" value="JS Alert"/> > </div> > > Java > ---- > import org.apache.tapestry5.RenderSupport; > import org.apache.tapestry5.annotations.AfterRender; > import org.apache.tapestry5.annotations.Environmental; > > public class JSAlert > { > private String alert = "function jsAlert() { alert(\"HELLO\"); }"; > > @Environmental > private RenderSupport renderSupport; > > @AfterRender > public void afterRender() { > renderSupport.addScript(alert); > } > } > > Basically, when you click the button, the browser says the JSAlert function > is not defined. > > TIA > > Lance > > -- > View this message in context: > http://www.nabble.com/-T5--Idiot-Javascript-question-tp20699079p20699079.html > Sent from the Tapestry - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- Andreas Andreou - [EMAIL PROTECTED] - http://blog.andyhot.gr Tapestry / Tacos developer Open Source / JEE Consulting --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]