• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help me about logic:iterate and javascript

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 51
Android Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, missed another example:

 
dang thanh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic