Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling a page element from a string.

    Hi,

    I haven't done any Javascript for a few years now but I'm sure I have found a way around this before.

    I have a table containing values. One of the TDs in each row has an input box so that users can input a value. When this changes I want to recalculate some of the other TDs in that row.

    I can get the row number from string manipulation of the input box source element ID. I then want to write back to the table using a row and column id name built from this ID.

    how do I use my new string so that I can assign a value to the page object of the same name?

    Thanks,

    Nick

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Something like this?
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <
    meta http-equiv="Content-Style-Type" content="text/css">
    <
    meta http-equiv="Content-Script-Type" content="text/javascript">
    <
    script type="text/javascript">
    function 
    calculate(inp){
    var 
    cells inp.parentNode.parentNode.getElementsByTagName('td');
    cells[4].firstChild.data Number(inp.value)+Number(cells[2].firstChild.data)
    }
    </script>
    </head>
    <body>
    <table width="250" border="0" cellspacing="2" cellpadding="2">
    <tr> 
    <td> <input name="textfield" type="text" size="5" onkeyup="calculate(this)"> </td>
    <td>+</td>
    <td>10</td>
    <td>=</td>
    <td>10</td>
    </tr>
    <tr> 
    <td> <input name="textfield" type="text" size="5" onkeyup="calculate(this)"> </td>
    <td>+</td>
    <td>20</td>
    <td>=</td>
    <td>20</td>
    </tr>
    <tr> 
    <td> <input name="textfield" type="text" size="5" onkeyup="calculate(this)"> </td>
    <td>+</td>
    <td>30</td>
    <td>=</td>
    <td>30</td>
    </tr>
    </table>

    </body>
    </html> 
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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