PDA

View Full Version : Getting value from function



melvinoyh
05-26-2006, 04:13 AM
for example this function get a value from a textbox and calculate and return the value to another textbox. this example can work.
-------------------------------------
<script type="text/javascript">

function chkBreakdown(){
myForm=document.brk

total=50*myForm.brkID.value
myForm.brk_total.value=total;
}

</script>

<html>
<body>
<form name="brk">
<input type="text" name="brkID" value="0" size="3" maxlength="3" onblur="chkBreakdown()">
<input type="text" name="brk_total">
</form>
</body>
</html>
------------------------------------------

now my problem is for example below:

Vector wp = new Vector();
Vector ln = new Vector();

<script type="text/javascript">

function chkBreakdown(wp,ln,la){
myForm=document.brk
total=wp+ln+la+*myForm.brkID<%=c%>.value <--is this correct or not?
myForm.brk_total.value=total;
}

</script>

<html>
<body>
<form name="brk">

<tr><td>LA no.</td><td>: <input type=text id="laNo" size=6 style="border:0" value='<%=la_no%>'> </td></tr>

<%for(int c=0; c<wp.size(); c++){%>
<td><input type="text" size=5 name="wp<%=c%>" value='<%=wp.elementAt(c)%>'></td>
<td><input type="text" size=4 name="ln<%=c%>" value='<%=ln.elementAt(c)%>'></td>
<td><input type="text" size=8 name="brkID<%=c%>" id="brkID" value='<%=brkID.elementAt(c)%>' onFocus="chkBreakdown('<%=wp.elementAt(c)%>','<%=ln.elementAt(c)%>','<%=la_no%>');"></td>
</form>
<input type="text" name="brk_total">
</body>
</html>

Twey
05-26-2006, 11:53 AM
total=wp+ln+la+*myForm.brkID<%=c%>.value <--is this correct or not?No, c isn't defined.

And you never actually closed that for loop. You're still mixing up Java (JSP, in this case) and Javascript. Don't. They are totally different, running at totally different locations, and they cannot directly interact with one another. The JSP runs first; think about whether your Javascript will make sense if you replace all the JSP with the values it should output.