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
    Feb 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question how do I use a function with a database results

    I have a database results that displays 3 text boxes across a table and as
    many rows as the query returns. I have a function that will allow you to
    enter a number in the first and second textbox then the function will add the numbers together and display it in the third textbox but it wont work if I
    display more than one row. I need to know how to code the textboxes and
    the function so It will increment the name values down the table here is a
    sample of the function I am using
    <script language="javascript">

    function Totals() {
    with (document.forms["form1"])
    {
    var total1 = Number( box1.value ) + Number( box2.value );

    box3.value = total1;

    }
    }
    </script>

    the html code is
    <table border="1" width="100%" id="table1">
    <tr>
    <td><input onblur=Totals() type=text name=box1 value=1></td>
    <td><input onblur=Totals() type=text name=box2 value=1></td>
    <td><input type=text name=sub_total value="?" readonly onfocus="this.blur()"></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    I dont show the database query that generates the rows
    but I think box1 needs box1++1 or something. Please help if you can

    Thanks
    Dave

  • #2
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am a newbie in Javascript and have made somthing similar..

    <head></head>
    Code:
    <script language="JavaScript">
    <!--
    function temp(form)
    {
      var f = parseFloat(form.box1.value, 0);
      var g = parseFloat(form.box2.value, 0);
      var c = 0;
      c = f + g;
      form.box3.value = c;
    }
    //-->
    </script>
    <body></body>
    Code:
    <FORM>
    <INPUT NAME="box1" VALUE="0" MAXLENGTH="15" SIZE=15> 
    + 
    <INPUT NAME="box2" VALUE="0" MAXLENGTH="15" SIZE=15>
    <INPUT VALUE="=" TYPE=BUTTON onClick=temp(this.form)>
    <INPUT NAME="box3" READONLY SIZE=15>
    </FORM>
    Here is an example of what it would look like.

    I used a different form of coding on this one. But i beleve the result is the same you are looking for. (I hope)


    EDIT:

    Noticed the frame part. Personally, i learn best when studying complete scripts rather than having to search online not knowing what to search after.

    Example Frames

    Code:
    <html>
    <head>
    <script language="JavaScript">
    <!--
    function temp1(form)
    {
      var f = parseFloat(form.box1.value, 0);
      var g = parseFloat(form.box2.value, 0);
      var c = 0;
      c = f + g;
      form.box3.value = c;
    }
    function temp2(form)
    {
      var f = parseFloat(form.box13.value, 0);
      var g = parseFloat(form.box23.value, 0);
      var c = 0;
      c = f + g;
      form.box33.value = c;
    }
    function temp3(form)
    {
      var f = parseFloat(form.box12.value, 0);
      var g = parseFloat(form.box22.value, 0);
      var c = 0;
      c = f + g;
      form.box32.value = c;
    }
    //-->
    </script>
    </head>
    <body>
    <FORM>
      Visible Frames: <br>
      <br>
      <table width="123" border="1" cellpadding="0" cellspacing="0">
      <tr>
        <th width="27" scope="row">&nbsp;</th>
        <td width="90"><input name="box1" value="0" maxlength="15" size=15></td>
      </tr>
      <tr>
        <th scope="row">+</th>
        <td><input name="box2" value="0" maxlength="15" size=15></td>
      </tr>
      <tr>
        <th scope="row"><input name="BUTTON" type=BUTTON onClick=temp1(this.form) value="="></th>
        <td><input name="box3" value="?" size=15 readonly></td>
      </tr>
    </table>
      <br>
      <br>
      Even more visible frames:<br>
      <br>
      <table width="123" border="1">
        <tr>
          <th width="27" scope="row">&nbsp;</th>
          <td width="90"><input name="box13" value="0" maxlength="15" size=15></td>
        </tr>
        <tr>
          <th scope="row">+</th>
          <td><input name="box23" value="0" maxlength="15" size=15></td>
        </tr>
        <tr>
          <th scope="row"><input name="BUTTON3" type=BUTTON onClick=temp2(this.form) value="="></th>
          <td><input name="box33" value="?" size=15 readonly></td>
        </tr>
      </table> 
      <br>
      <br>
      Invisible Frames:<br>
      <br>
      <table width="131" border="0">
        <tr>
          <th width="25" scope="row">&nbsp;</th>
          <td width="90"><input name="box12" value="0" maxlength="15" size=15></td>
        </tr>
        <tr>
          <th scope="row">+</th>
          <td><input name="box22" value="0" maxlength="15" size=15></td>
        </tr>
        <tr>
          <th scope="row"><input name="BUTTON2" type=BUTTON onClick=temp3(this.form) value="="></th>
          <td><input name="box32" value="?" size=15 readonly></td>
        </tr>
      </table>
    </FORM>
    </body>
    </html>
    Hmm...
    Last edited by Akimoto°; 02-23-2007 at 03:09 AM.


  •  

    Posting Permissions

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