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 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Location
    Tampa, Fl
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question textfield divided into textfield = a third field

    New.. where should I begin? I have a form that has 2 text fields that need to be divided by each other once a person enters the amounts and the result to be placed in a third text field?
    Thanks
    H-

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    SC
    Posts
    936
    Thanks
    0
    Thanked 0 Times in 0 Posts
    why dont u alert the value, and make it easy on urselve

    ...

  • #3
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It would be better to see your code, but anyway...

    Code:
    ...
    <script>
    function divideFields() {
     txt3.value = txt1.value / txt2.value;
    }
    </script>
    
    <input type="text" id="txt1" name="txt1"/>
    /
    <input type="text" id="txt2" name="txt2"/>
    =
    <input type="text" id="txt3" name="txt3"/>
    ...
    I think that should do it.

    Sadiq.

  • #4
    New to the CF scene
    Join Date
    Mar 2004
    Location
    Tampa, Fl
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, this is what I have. I cant understand how to get it to caculate...

    <script language="JavaScript" type="text/JavaScript">
    <!--
    function divideFields() {
    ltv.value = Aleft.value / Hval.value;
    }
    //-->
    </script>

    <input name="Hval" type="text" id="Hval">
    <input name="Aleft" type="text" id="Aleft">
    <input name="lvt" type="text" id="lvt">
    Thanks
    H-

  • #5
    New Coder
    Join Date
    Jun 2002
    Location
    England, UK
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by Hrub
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function divideFields() {
    ltv.value = Aleft.value / Hval.value;
    }
    //-->
    </script>

    <input name="Hval" type="text" id="Hval">
    <input name="Aleft" type="text" id="Aleft">
    <input name="lvt" type="text" id="lvt">
    assuming you copied this directly from your page - the fields are spelt differently so that is you're reason.

    also for clarity, you don't need both the name and id fields for an element, it would be clearer with just the one attribute used.

  • #6
    New to the CF scene
    Join Date
    Mar 2004
    Location
    Tampa, Fl
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks,
    fixed that and took out the name field.

    I dont understand... I type in 100 in the first box, 2 in the second box and the third box still doesnt caculate the answer.

    Please help me understand why
    Thanks
    H-

  • #7
    New Coder
    Join Date
    Jun 2002
    Location
    England, UK
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this is how i got it working:

    Code:
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function divideFields() {
    num1 = Aleft.value
    num2 = Hval.value
    
    lvt.value = eval(num1 / num2)
    }
    //-->
    </script>
    
    <input name="Aleft"> / <input name="Hval">
    
    <br><input name="lvt"><br><br>
    <a href="javascript:divideFields()">Do Sum</a>
    slightly more clear like that

    EDIT: For some reason the forum is showing a space between java and script in the href attribute (???) not exactly sure why (i didnt put it there, and its not showing up in the edit field) but it should be spelt as one word i.e: javascript
    Last edited by dd/mm/yy; 03-11-2004 at 05:00 PM.

  • #8
    New to the CF scene
    Join Date
    Mar 2004
    Location
    Tampa, Fl
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I noticed java and script were spaced and fixed that.
    When I hit do sum, I get an error on page?

    Is it me???

    EDIT:
    OK it does work. My text boxes are in a form.. which made it not work. How do i get that to work?

    I guess it was me.
    Last edited by Hrub; 03-11-2004 at 05:32 PM.
    Thanks
    H-

  • #9
    New Coder
    Join Date
    Jun 2002
    Location
    England, UK
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    to get it to work with a form you need

    document.FORMNAME.Aleft.value

    where FORMNAME is the name of your form (i'm known for statin the obvious! )

  • #10
    New to the CF scene
    Join Date
    Mar 2004
    Location
    Tampa, Fl
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah!!!!! It works
    You dont know how happy I am!!!!
    Thanks
    H-

  • #11
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Warning: offtopic.
    Originally posted by dd/mm/yy
    also for clarity, you don't need both the name and id fields for an element, it would be clearer with just the one attribute used.
    Au contraire, daymonthyear. Each is required for different purposes. Form elements without a name attribute are not submitted in the HTTP request; form elements without an id attribute are not usable with elements like label, and force one to use the form[formname].elements[elementname] reference, completely disabling document.getElementById(elementname) references.

    Clarity is not endangered by utilizing two attributes which have different purposes.

  • #12
    New Coder
    Join Date
    Jun 2002
    Location
    England, UK
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i stand corrected.


  •  

    Posting Permissions

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