SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    determine which field was changed

    supposing I have 3 text boxes in an html doc, Textbox A, B, and C. I want to create a little calculator that will do the following

    c=a*b
    a=b/c

    Is their a way to test to determine which text box was last changed, so I can apply the correct formula to solve the problem.

  2. #2
    SitePoint Evangelist hexburner's Avatar
    Join Date
    Jan 2007
    Location
    Belgium
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var lastChanged = null;
    
    function onChange(el) {
        lastChanged = el;
    }
    
    function doCalculations() {
        if (lastChanged != null) {
            // Calculations here
        }
    }
    Code:
    <input id="A" type="text" onchange="onChange(this);"/>
    <input id="B" type="text" onchange="onChange(this);"/>
    <input id="C" type="text" onchange="onChange(this);"/>
    <input type="button" onclick="doCalculations();"/>
    FOR SALE: 1 set of morals, never used, will sell cheap


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
  •