0
votes

Update: code reduced and further description about this web application that I am trying to do.

<xp:text escape="true" id="computedField1">
    <xp:this.value><![CDATA[#{javascript: sessionScope.DishNameValue;
}]]></xp:this.value>
</xp:text>
<xp:br></xp:br>
<xp:br></xp:br>
&#160;<xp:table style="width:636.0px">
    <xp:tr>
        <xp:td style="width:250.0px">
            <xp:inputTextarea id="inputTextarea2">
                <xp:this.value><![CDATA[#{javascript:
var selectedDishNameRestaurant =  @DbLookup(@DbName(),"RestaurantDishNameView",   (getComponent("computedField1").getValue()),3) 
if(selectedDishNameRestaurant != null)
{
    return selectedDishNameRestaurant;
}
else
{
    return "nothing here"
}
}]]></xp:this.value>
                <xp:this.multipleSeparator><![CDATA[#{javascript:"\n"}]]></xp:this.multipleSeparator>
                <xp:this.rendered><![CDATA[#{javascript:if(getComponent("computedField1").getValue() != null)
{
    return true;
}}]]></xp:this.rendered>
            </xp:inputTextarea>
        </xp:td>
        <xp:td style="width:250.0px">
            <xp:inputTextarea id="inputTextarea4">
                <xp:this.value><![CDATA[#{javascript:var selectedDishNameRestaurant = @DbLookup(@DbName(),"RestaurantDishNameView", (getComponent("computedField1").getValue()),3) 
var createdDishValue = @DbLookup(@DbName(),"CreatedDishView", selectedDishNameRestaurant,2); 
var restaurantDishValue = @DbLookup(@DbName(),"RestaruantDishView", createdDishValue,1);

if(creatededDishValue !=null){
return "Yes";
}
else
{ 
    return "No";
}


}]]></xp:this.value>
                <xp:this.multipleSeparator><![CDATA[#{javascript:"\n"}]]></xp:this.multipleSeparator>
                <xp:this.rendered><![CDATA[#{javascript:if(getComponent("computedField1").getValue() != null)
{
    return true;
}}]]></xp:this.rendered>
            </xp:inputTextarea>
        </xp:td>
        <xp:td style="width:250.0px">
            <xp:inputTextarea id="inputTextarea6">
                <xp:this.value><![CDATA[#{javascript:var   selectedDishNameRestaurant = @DbLookup(@DbName(),"RestaurantDishNameView",  (getComponent("computedField1").getValue()),3) 
var createdDishValue = @DbLookup(@DbName(),"CreatedDishView", selectedDishNameRestaurant,2); 
var restaurantDishValue = @DbLookup(@DbName(),"RestaruantDishView", createdDishValue,1);
var createdDate = @DbLookup(@DbName(),"RestaruantDishView", createdDishValue,2);
if(createdDishValue !=null){
return createdDate;
}
else
   { 
        return "";
    }
    }]]></xp:this.value>
                <xp:this.multipleSeparator><![CDATA[#{javascript:"\n"}]]></xp:this.multipleSeparator>
                <xp:this.rendered><![CDATA[#{javascript:if(getComponent("computedField1").getValue() != null)
{
    return true;
}}]]></xp:this.rendered>
            </xp:inputTextarea>
        </xp:td>
    </xp:tr>
</xp:table>

In the first page:

  • The user will select the dish name or style (use radio button group and combo box) for the display it in the second page. (This part works fine)

In the second page:

  • There will be a computed field to display the selected value.(This part works fine because I use session variable to store the value)

  • There is a multi line edit box, it will display values in separate lines depends on the computed field's value. For example if the user select the dish name, then it will display which restaurant(s) has this dish. In this part, I use @DbLookup to achieve at this stage, the program still works fine).

  • There is another multi line edit box. it display values depends on the first multi line edit box. For example, the first multi line edit box can display a list of restaurants that has the specific dish name(selected by the user). The second multi line edit box will display the value that whether the restaurant has created the dish or not, if the the restaurant created the dish, the value return "Yes", otherwise return "No".

In this part, no matter how many values in the first multi line edit box, I could only get one "Yes" or one "No" in the second multi line edit box.

Would someone let me know how to make the second multi line edit box to display all values please? Thank you.

I tried to use for loop but not work.

for (i = getComponent("inputTextarea2").getValue(); i < getComponent("inputTextarea2").length; i++)
1
Please reduce your code to a minimum: stackoverflow.com/help/mcve This will help you to get an answer.Knut Herrmann
The whole content is edited: reduce code and improve content. Sorry for the inconvenienceLearner
For what you look like you are doing, check out repeats. Multi-line edits are designed more for entry than display. You can set the values in your first repeat (your 1st muliline field) to pass the selected value to you second and refresh your second repeat. There are many examples out there to show you.Brian M Moore

1 Answers

0
votes

Disclaimer: I prefer the following information should be a comment but I don't have enough rights to do that.

Here is my thought the reason why you only have one "Yes" or "No" for the result is in this part: (if my concept is wrong, please correct me)

if(creatededDishValue !=null){
    return "Yes";
 }
else
{ 
    return "No";
}

Because createdDishValue is not null, it will return "Yes", so if the @DbLookup calculation is correct, it will lookup a value. So if there are 10 values, the result will only display 1 "Yes" or 1 "No". Therefore, if you need to return 10 Yes/No, you need to do some programming to achieve that.

Please note: I haven't try your for loop code yet but I would recommend you to have a look at this website: JavaScript for...in loop

According to the website, it mentioned

The for...in loop is used to loop through an object's properties.

So how about try to use for in loop instead of for loop in your code?

Thank you.