Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2014
    Posts
    17
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Test Drive stupidos

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    
    <script>
    new function=myfunction2(){
    alert("hello");
    }
    </script>
    
    
    
    <form name="form2">
      <select name="menu1" onChange="myfunction2()">
        <option>one</option>
        <option>two</option>
        <option>three</option>
      </select>
    </form>
    
    
    
    
    
    
    
    </body>
    </html>

    a stupid test, why doesnt it alert the simple message "hello" ?? i change alert for console.log, doesnt work. i change it for trace, doesnt work, i change it for prompt, doesnt work . it get me on nerves real fast . im working on a much higher project and even the alert dont worlk

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,112
    Thanks
    38
    Thanked 498 Times in 492 Posts
    Get rid of the "new function =" portion of your code, as in ...
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    
    <script>
    function myfunction2(){
    alert("hello");
    }
    </script>
    
    
    
    <form name="form2">
      <select name="menu1" onChange="myfunction2()">
        <option>one</option>
        <option>two</option>
        <option>three</option>
      </select>
    </form>
    </body>
    </html>
    Always a good idea to match all tags ( <body> </body> and <html> </html> )
    Also check the error console if using FF or Chrome browsers. Located the problem to line 12 for me.

    If you really want to make the variable the function, you could do this as well ....
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    
    <script>
    var myfunction2 = function(){
    alert("hello");
    }
    </script>
    
    <form name="form2">
      <select name="menu1" onChange="myfunction2()">
        <option>one</option>
        <option>two</option>
        <option>three</option>
      </select>
    </form>
    </body>
    </html>
    Good Luck on your project.
    Last edited by jmrker; 07-20-2014 at 12:47 AM.


  •  

    Posting Permissions

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