aspose file tools*
The moose likes Struts and the fly likes help me about logic:iterate and javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "help me about logic:iterate and javascript" Watch "help me about logic:iterate and javascript" New topic
Author

help me about logic:iterate and javascript

dang thanh
Greenhorn

Joined: Oct 10, 2012
Posts: 2
Hello every body
Iam a newbie

Iam using struts1 and i have a ploblem want to ask you

When i use a script to automate add two numbers from 2 textfield, i use a script and code like this and it work properly
Num1 : <html:text property="num1" onkeyup="calc()" value=""/>
<br>
Num2 : <html:text property="num2" onkeyup="calc()" value=""/>
<br>
Num3 : <html:text property="num3" value=""/>


But if i want to do this in many lines, i use a loop by logic:iterate tag:



<logic:iterate id="listUser" name="UserActionForm" property="listUser">
Num1 : <html:text name="listUser" property="num1" value="${listUser.num1}"
indexed="true" onkeyup="calc()"/>

Num2 : <html:text name = "listUser" property="num2" value="${listUser.num2}"
indexed="true" onkeyup="calc()"/>

Num3 : <html:text name="listUser" property="num3" indexed="true"/>
<br>
</logic:iterate>


and it doesn't work

sorry, this is my script

<script type="text/javascript">
function calc()
{
var num1 = document.forms[0].num1.value;
var num2 = document.forms[0].num2.value;
if(num1 != "" && num1.length!= 0 && num2!="" && num2.length != 0){
var num11 = parseInt(num1);
var num22 = parseInt(num2);
document.forms[0].num3.value = num11*num22;
} else{
document.forms[0].num3.value = "";
}
}
</script>


so, can you show my mistakes and how to fix them
Thanks so much
Tarun Trehan
Ranch Hand

Joined: Mar 16, 2012
Posts: 48

You can use JSTL for this.
The following code works.



Thanks,
Tarun Trehan (http://allzhere.in)
Tarun Trehan
Ranch Hand

Joined: Mar 16, 2012
Posts: 48

Sorry, missed another example:

dang thanh
Greenhorn

Joined: Oct 10, 2012
Posts: 2
thanks Tarun Trehan
Can you explain more about the properties in your code
iam using struts, i really don't understand your code
Thanks again
 
jQuery in Action, 2nd edition
 
subject: help me about logic:iterate and javascript
 
Similar Threads
Java Script problem
Javascript and Struts Indexed Text Boxes
Testing for true or false
Iterate indexId + Indexed Form + Javascript
how to use indexid of logic:iterate tag in struts