The error is Object expected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mike1961
    New Member
    • Apr 2008
    • 66

    The error is Object expected

    Hi all.

    Why this script not working?

    The error is Object expected in the line:

    var new_ = concat(concat(o re,":"), min);

    Code:
    <html>
    
    <head>
    <script>
    
    function insertColon(id){
    var stringa = document.getElementById(id).value;
    var ore = stringa.substr(0,2);
    var min = stringa.substr(2,2);
    
    var new_ = concat(concat(ore,":"), min);
    
    document.getElementById(id).value = new_;
    }
    </script>
    </head>
    
    <body>
    
    <input id="testo" type="text" name="ora" size="5" onchange="java-script:insertColon('testo')"/>
    
    </body>
    
    </html>
    Can you help me?
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Get rid of "java-script:" - you don't need it and even if you were to use it, it would be "javascript ".

    Where is concat defined?

    Comment

    • Mike1961
      New Member
      • Apr 2008
      • 66

      #3
      thanks acoder x your reply, but error of copy/paste.

      The error is same.

      Code:
      <html>
      
      <head>
      <script>
      
      function insertColon(id){
      var stringa = document.getElementById(id).value;
      var ore = stringa.substr(0,2);
      var min = stringa.substr(2,2);
      
      var new_ = concat(concat(ore,":"), min);
      
      document.getElementById(id).value = new_;
      }
      </script>
      </head>
      
      <body>
      
      <input id="testo" type="text" name="ora" size="5" onchange="javascript:insertColon('testo')"/>
      
      </body>
      
      </html>

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        concat is not defined. Did you mean to use the String object's concat() method?

        Comment

        • Mike1961
          New Member
          • Apr 2008
          • 66

          #5
          Concat is for joining arrays.

          Its working now, many thanks.

          Code:
          <html>
          
          <head>
          <script>
          
          function insertColon(id){
          	var stringa = document.getElementById(id).value;
          	var ore = stringa.substr(0,2);
          	var min = stringa.substr(2,2);
          	
          	var new_ = ore + ":" + min;
          	document.getElementById(id).value = new_;
          }
          </script>
          </head>
          
          <body>
          
          <input id="testo" type="text" name="ora" size="25" onchange="javascript:insertColon('testo')"/>
          
          </body>
          
          </html>

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            ...and for strings, e.g.
            [code=javascript]var new_ = ore.concat(":", min);[/code]Anyway, glad it's working.

            Comment

            Working...