answered
2013-08-27 08:53:14 +0800
cor3000 6280 ● 2 ● 7 Hi,
thanks for the details, that makes the explanation simple, as your way of adding JS is actually working.
The server side <textbox>
component is being rendered with a generated ID at the <input>
element (just check the element in firebug, and you'll see something like this: <input id="tY8Q1" class="z-textbox" value="HAI" type="text">
).
Using document.getElementById("tY8Q1") would work, but only once. The next time the page is rendered the ID will be different.
ZK is also creating a client side widget which keeps the ID of the server side component (refer to this image).
You can use the ZK Client Engine API to retrieve the Widget by the ID defined in the zul file.
zk.Widget.$('$hai').getValue();
If you just need the corresponding DOM element you can use:
zk.Widget.$('$hai').$n();
So a complete running example here:
<zk>
<window>
<textbox id="hai" value="HAI"></textbox>
<button id="export" label="Click" onClick='Clients.evalJavaScript("myFunction()")'>
</button>
<script type="text/javascript">
function myFunction()
{
document.body.style.backgroundColor="lavender";
<!-- document.write(Date()); -->
alert(zk.Widget.$("$hai").getValue());
}
</script>
</window>
</zk>
Robert