www.webdeveloper.com
Results 1 to 5 of 5

Thread: Uncaught typeerror

  1. #1
    Join Date
    Apr 2005
    Location
    Roma (Italia - Italy)
    Posts
    16

    Uncaught typeerror

    Hi,
    i'm tring for hours to correct this simple script:
    Code:
        <script language="javascript" type="text/javascript">
    	function music(act, id, dis) {
    		if(dis.length <= 1) { var s = 'non impostato'; } else { var s = '<a href="storage/music/' + dis +'" target="_blank">' + dis + '</a>'; }
    		if(act == 'new') {
    			document.getElementById('music' + id).innerHTML = s + ' &bull; <input type="file" name="music" /> <a href="javascript:void(0);" onclick="music(\'back\', ' + id + ', \'' + dis + '\');">Non cambiare</a>';
    		}
    		else {
    			document.getElementById('music' + id).innerHTML = s + ' &bull; <a href="javascript:void(0);" onclick="music(\'new\', ' + id + ', \'' + dis + '\');">Cambia musica</a>';
    			}
    	}
        </script>
    Javascript says:
    Uncaught typeerror: object is not a function
    General HTML code:
    Code:
        <form action="/ad/pubsis/pubsis.php" method="post" enctype="multipart/form-data">
          <table>
            <tr>
              <td>1</td>
              <td><div id="music30">non impostato &bull; <a href="javascript:void(0);" onclick="music('new', '30', '0');">Cambia musica</a></div></td>
            </tr>
          </table>
        </form>
    -----------
    Now i found that if i remove
    Code:
    <input type="file" name="music" />
    from code, the script works well.
    What can i do to fix that?

  2. #2
    Join Date
    Dec 2005
    Posts
    2,984
    Some browsers - cough, IE - might take the name attribute of certain elements and make them global variables.

    So what's happening is when the file input with name music element is created, then window.music refers to an DOM element and not a function.

    Just give your file input a different name.

    What browsers are giving you this problem, by the way?

    EDIT: Looking at this thread in stackoverflow (http://stackoverflow.com/questions/3...with-name-attr) you might be able to use the same name attribute if you modify your function to look like this:

    Code:
    var music = function(act, id, dis) {
     /* your code here */
    }

  3. #3
    Join Date
    Apr 2005
    Location
    Roma (Italia - Italy)
    Posts
    16
    yes: it's always a good approach with machines try to change names, but all this time lost made me too angry to think. so... i lost a day of work just for a name.
    (just for fun: IE detects the problem but script worked the same... chrome stops execution instead)

    however, my theory is confirmed. scopes suck.
    Last edited by Wider; 07-16-2012 at 03:14 PM.

  4. #4
    Join Date
    Dec 2005
    Posts
    2,984
    So....does that mean the problem is fixed?

  5. #5
    Join Date
    Apr 2005
    Location
    Roma (Italia - Italy)
    Posts
    16
    yes thank you

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles