0

Javascript + ZK

asked 2012-03-08 10:15:36 +0800

oliverhernandez gravatar image oliverhernandez
12

Hi,

How could I get a value of ZK Component to use it in javascript code which uses ajax Request? I need value of a ZK Component which will be a param in the ajax Request.

In my code:


<n:script src="/resources/jquery.js"/>
<n:script>
<![CDATA[
$.getJSON("http://url/getInfo.php?tags=cat&tagmode=any&format=json&jsoncallback=?",
{
tags: "cat",
tagmode: "any",
format: "json"
},
function(data) {
$.each(data.items, function(i,item){
alert('title:' + item.title);
if ( i == 0 ) return false;
});
});
]]>
</n:script>

I'd like get value of param 'tags' from ZK Component.

Thanks all

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2012-03-08 11:30:03 +0800

mhj gravatar image mhj flag of Brazil
806 1 7

updated 2012-03-08 11:33:16 +0800

hi oliver
look the follows links:
http://books.zkoss.org/wiki/Small_Talks/2010/April/Client_Side_Programming
http://books.zkoss.org/wiki/ZK_Client-side_Reference
and codes below:

ZKFiddle-Link

index.zul
<zk xmlns:w="client">
<label id="tb" width="250px" value="hello" >
<custom-attributes org.zkoss.zk.ui.updateByClient="true"/>
</label>
<button label="chage at client-side">
<attribute w:name="onClick"><![CDATA[
var tb = zk.Widget.$(jq('$tb')),
val = 'world';
tb.setValue(val);
tb.smartUpdate('value', val);
]]></attribute>
</button>
<button label="get at server-side" onClick="alert(tb.value)"/>
</zk>


TestComposer.java
package j173cqqt$v1;

import org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.au.*;
import org.zkoss.zk.au.out.*;
import org.zkoss.zul.*;

public class TestComposer extends GenericForwardComposer{

public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);

}

public void onClick$btn(Event e) throws InterruptedException{
Messagebox.show("Hi btn");
}
}


index.zul
<zk>
<script>
function testjq(widget){
jq(widget).attr('disabled', true);
}
</script>
<window border="normal" title="hello" apply="j173cqqt$v1.TestComposer" xlmns:w="client">

<div>Welcome to ZK Fiddle , run it right now!</div>

<button label="Click Me To disable textbox using jquery" w:onClick="testjq(jq('$tb'))"/>
<textbox id="tb"/>
</window>
</zk>

i hope that help you...

link publish delete flag offensive edit

answered 2012-03-09 11:15:05 +0800

oliverhernandez gravatar image oliverhernandez
12

Thanks for the examples!

I get the solution with 'Clients.evalJavaScript(jsMethod)' which calls the jsMethod in the client.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-03-08 10:15:36 +0800

Seen: 274 times

Last updated: Mar 09 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More