• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help me about logic:iterate and javascript

 
dang thanh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
Android Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use JSTL for this.
The following code works.

 
Tarun Trehan
Ranch Hand
Posts: 51
Android Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, missed another example:

 
dang thanh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic