Results 1 to 2 of 2

Thread: Getting value from function

  1. #1
    Join Date
    May 2006
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Getting value from function

    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>

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •