SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Doesnt Work in FireFox

    I have some Javascript that takes the input from some textboxes and then puts them all into a sentance automatically. It works perfectly in IE but not with FireFox... does anyone know how to make it work with both browsers?

    HTML Code:
    <script type="text/javascript">
    function Text_Change() {
      var TxtFName = document.getElementById("TxtFName");
      var TxtSName = document.getElementById("TxtSName");
      var TxtAge = document.getElementById("TxtAge");
      var TxtLoc = document.getElementById("TxtLoc");
    
      var SpnDisp = document.getElementById("SpnDisp");
    
      var FName = TxtFName.value == "" ? "?" : TxtFName.value;
      var SName = TxtSName.value == "" ? "?" : TxtSName.value;
      var Age = TxtAge.value == "" ? "?" : TxtAge.value;
      var Loc = TxtLoc.value == "" ? "?" : TxtLoc.value;
    
      SpnDisp.innerHTML =
        "Hello " + FName + " " + SName + ", " +
        "you are " + Age + " years old and " +
        "at the moment you live in " + Loc;
    }
    </script>
    
    <body onload="Text_Change()">
    
    <div><input type="text" id="TxtFName" onchange="Text_Change()" /></div>
    <div><input type="text" id="TxtSName" onchange="Text_Change()" /></div>
    <div><input type="text" id="TxtAge" onchange="Text_Change()" /></div>
    <div><input type="text" id="TxtLoc" onchange="Text_Change()" /></div>
    
    <div><span id="SpnDisp"></span></div>
    Turn My Text - íspuǝıɹɟ ʞooqǝɔɐɟ ɹnoʎ ǝzɐɯɐ puɐ ǝsnɟuoɔ

    Computer Game Cheats & Codes

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Try enclosing the input fields inside a <form>.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That fixed it - many thanks to you
    Turn My Text - íspuǝıɹɟ ʞooqǝɔɐɟ ɹnoʎ ǝzɐɯɐ puɐ ǝsnɟuoɔ

    Computer Game Cheats & Codes

  4. #4
    SitePoint Addict
    Join Date
    Apr 2003
    Posts
    332
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    <code>
    var FName = TxtFName.value == "" ? "?" : TxtFName.value;
    </code>

    Will you explain this line of code to me?
    Thanks,

    Andy

  5. #5
    SitePoint Addict jtrelfa's Avatar
    Join Date
    Oct 2004
    Location
    Troy, Mi
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 1andyw
    Hi,
    Code:
    var FName = TxtFName.value == "" ? "?" : TxtFName.value;
    Will you explain this line of code to me?
    Thanks,

    Andy
    It's called the 'ternary' operator. It's a shortcut way to type this:
    Code:
    var FName;
    if (TxtFName.value == "") {
      FName = "?";
    } else {
      FName = TxtFName.value;
    }
    HTH,

    Jon

  6. #6
    SitePoint Addict
    Join Date
    Apr 2003
    Posts
    332
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, Jon.

    You did a nice job of making that simple.

    Andy


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
  •