0

RE: Client Side Programming - Javascript - eval()

asked 2010-08-24 14:07:49 +0800

vpupkin gravatar image vpupkin
30 1

After compilation this Doc-Page my HelloZK looks like:

<window id="win" border="normal" width="600px" xmlns:w="http://www.zkoss.org/2005/zk/client">
<textbox id="textToEval" value ="1+2"  onChanging="resultLabel.value=event.value"/>
<label value=" Hello ZKalkulator! Just try to edit expression in the text field to get result..." id="resultLabel">
            <attribute w:name="setValue">
            function (value) {
                  this.$setValue(value); //call the original method
                  if (this.desktop) {
                        this._flag = !this._flag;
                        this.setStyle('background:'+(this._flag ? 'red':'green'));
                        this.$setValue( eval ( ''+value+'') ) ;
                   }
            }
            </attribute>
</label>
</window>

So, its works (WONDERFULL even on ONLINE_DEMO!) as good as should...
.. till expr-eval-error. How can i process wrong expression-evaluation otherwise?

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2010-08-24 18:48:38 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi vpupkin
Why are you need do this ?

this.$setValue( eval ( ''+value+'') ) ;

link publish delete flag offensive edit

answered 2010-08-25 04:09:58 +0800

vpupkin gravatar image vpupkin
30 1

hi as1225!

I just need to evaluate some expression. Like a custom calculator with ZK. The Q is only - how to catch eny possible exceptions/errors on such evaluation. Is it possible?

link publish delete flag offensive edit

answered 2010-08-26 21:05:32 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

You can set the result into value

  <attribute w:name="setValue">
            function (value) {
                  this.$setValue(value); //call the original method
                  if (this.desktop) {
                        this._flag = !this._flag;
                        this.setStyle('background:'+(this._flag ? 'red':'green'));
                        val value;
                        try{
                           value  =  eval ( ''+value+'')
                        }catch(e){}


                        this.$setValue(value) ;
                   }
            }
            </attribute>

link publish delete flag offensive edit

answered 2010-08-31 15:19:14 +0800

vpupkin gravatar image vpupkin
30 1

Hi As1225,
thanks a lot for your Advice! Unfortunately its not works on my side. What version of ZK did you checked with your example?

Regards,
VPupkin

link publish delete flag offensive edit

answered 2010-08-31 19:41:23 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

I use ZK5
this feature only exits in ZK 5

link publish delete flag offensive edit

answered 2010-08-31 19:50:12 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

updated 2010-08-31 19:50:35 +0800

Sorry I have wrong words

try this in ZK demo

<window id="win" border="normal" width="600px" xmlns:w="http://www.zkoss.org/2005/zk/client">
<textbox id="textToEval" value ="1+2"  onChanging="resultLabel.value=event.value"/>
<label value=" Hello ZKalkulator! Just try to edit expression in the text field to get result..." id="resultLabel">
            <attribute w:name="setValue">
            function (value) {
                  this.$setValue(value); //call the original method
                  if (this.desktop) {
                        this._flag = !this._flag;
                        this.setStyle('background:'+(this._flag ? 'red':'green'));
                        var value;

                        try{
                           value  =  eval ( ''+value+'');
                        }catch(e){}


                        this.$setValue(value) ;
                   }
            }
            </attribute>
</label>
</window>

link publish delete flag offensive edit

answered 2010-09-13 14:08:05 +0800

vpupkin gravatar image vpupkin
30 1

updated 2010-09-13 14:08:25 +0800

WOW! It's works now! Great. 10x a lot!

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: 2010-08-24 14:07:49 +0800

Seen: 745 times

Last updated: Sep 13 '10

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