0

if statement

asked 2008-12-20 00:27:59 +0800

james gravatar image james
255 2

I think this is sad, but... I'm at a loss...
I am trying to do an if statement in a function and it's just not working.
I have a test.zul file and a test.zs file. in the zul file, I have this... <zscript src="test.zs" />
Ultimately what I want, is to have some variables that i want to change depending on what's selected in a listbox.
Then what's done in the function will vary depending on what the variable is.
But the if statement just isn't working.
some example code...


test.zul
<variables type="1" />
<zscript src="test.zs" />
<listbox id="LBtest" mold="select" rows="1">
    <listitem label="first" value="1"/>
    <listitem label="second" value="2"/>
    <listitem label="third" value="3"/>
    <attribute name="onSelect">
        self.setVariable("type", LBtest.getSelectedItem().getValue(), true);
    </attribute>
</listbox>
<button label="submit" onClick="submit()"/>

test.zul
void submit() {
    if (type == "1"){
    	alert("1");
    }
    if (type == "2"){
    	alert("2");
    }
    if (type == "3"){
    	alert("3");
    }
    if (type != null){
    	alert("null...  type == "+type);
    }
}



In the if statement, I have tried using single quotes, no quotes, and even assigning other variables with the values, and then referencing the various variables...
Ex:
self.setVariable("varA", 1, true);
if (Qtype == varA){
    alert("1");
}

I get a message saying "null... type == 1" (or 2 or 3, if that's what i have selected)
If I say ...
if (type != "3"){
(doing this with all of them, no quotes, single quotes and double quotes) then I get an alert.
I dont know how to reference these... the variable registers as no being null... but what is it?
Or my real question... how do check the variable against something...
How do I check to see if the variable type is equal to 1, 2 or 3 so that i can know what to do in my function?
Any and all help is greatly appreciated... Sorry for the long intro here, but I don't know how else to clearly ask my question...
thanks.

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2008-12-22 00:39:05 +0800

RyanWu gravatar image RyanWu
533 2
about.me/flyworld

updated 2008-12-22 00:39:18 +0800

I found a problem in your code

if (type == "1") 

when you using JAVA
make sure you check you string by using "String.equals(...)" not "=="

link publish delete flag offensive edit

answered 2008-12-22 19:12:49 +0800

james gravatar image james
255 2

Great, thank you very much.

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: 2008-12-20 00:27:59 +0800

Seen: 725 times

Last updated: Dec 22 '08

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