PDA

View Full Version : alert text


wenjin_h
08-09-2004, 02:21 PM
I try to change the alert's message by script function. I tried couples of different way, none of them works. The following is the source code.

--------------------------------------

<canvas height="140">
<script>
<![CDATA[
function openAlert()
{
canvas.myalert.setVariable(text, "NEW");
canvas.myalert.setText("NEW");
canvas.myalert.text= "NEW";
canvas.myalert.content= "NEW";
canvas.myalert.open();
}
]]>
</script>

<alert name="myalert">OLD</alert>

<button onclick="openAlert()">Show Alert</button>
</canvas>

--------------------------------------

Does anyone know how to set the alert message at run time? Thanks.

antun
08-09-2004, 02:40 PM
It's alert.alerttext.setText():


<canvas height="140">

<alert name="myalert">OLD</alert>

<button>Show Alert
<method event="onclick">
canvas.myalert.alerttext.setText("NEW");
canvas.myalert.open();
</method>
</button>
</canvas>


I note that it's not well documented in the reference. I looked at the source code for the alert class, which is declared in window.lzx in:

WEB-INF/lps/components/lz/

To tell you the truth, alert should really have a setText() method - my suggestion above is really more of a hack: you should not need to know the inner workings of a class in order to use it. To be a little more elegant, you could subclass alert and write the extra method:


<class name="myalert" extends="alert">
<method name="setText" args="t">
this.alerttext.setText( t );
</method>
</class>


... then you could just use the <myalert /> tag instead.

One other thing - setVariable() is not a method, it's setAttribute, but it doesn't help you here.

Take care,

Antun

wenjin_h
08-10-2004, 07:05 AM
It works. Thank you very much.

ebrentnelson
02-13-2006, 05:21 PM
I noticed that:

myAlert.setAttribute('text','alert string');

works too.

ebn

antun
02-13-2006, 07:21 PM
Yes - actually that's better than referencing children of the alert class, as in my example. <alert> is missing a setter method for the text attribute.

-Antun

Originally posted by ebrentnelson
I noticed that:

myAlert.setAttribute('text','alert string');

works too.

ebn