Can I shorten this syntax?

Discussion in 'JavaScript' started by val75, Jan 3, 2009.

  1. #1
    Hi.

    Can I shorten this syntax it doesn't look elegant,
    I tried to do that but always I got more and more code.
    Please help.

    x.text3.value = x.text1.value - x.text2.value;

    <form name="Form1">
    Variable 1: <input type="text" name="text1" value="variable1">
    Variable 2: <input type="text" name="text2" value="variable2">
    Equal: <input type="text" name="text3" value="equal">
    </form>
     
    val75, Jan 3, 2009 IP
  2. cont911

    cont911 Peon

    Messages:
    50
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <head>
    <script>
    function somethingChanged()
    {
    val1 = document.getElementById("val1");
    val2 = document.getElementById("val2");
    val3 = document.getElementById("val3");
    val3.value = val1.value + val2.value;
    }
    </script>
    </head>

    <form name="Form1" >
    Variable 1: <input type="text" name="text1" value="variable1" id="val1" onchange="somethingChanged()" >
    Variable 2: <input type="text" name="text2" value="variable2" id="val2" onchange="somethingChanged()" >
    Equal: <input type="text" name="text3" value="equal" id="val3" onchange="somethingChanged()" >
    </form>
     
    cont911, Jan 4, 2009 IP
  3. val75

    val75 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That's great.
    Thanx
     
    val75, Jan 4, 2009 IP