50 users online (1 members and 49 guests)  


  Results 1 to 2 of 2

Related

  1. Javascript's call back function    Forum: Javascript Forum
    Replies: 0
  2. Replies: 1
  3. call external Javascript(PHP) with passing value    Forum: Javascript Forum
    Replies: 2
  4. Replies: 5
  1. #1
    deekshas's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2009
    Posts
    2

    Javascript function call

    The function change() in not getting called by onClick event of button Click Me,JavaScript array

    size has been created in PHP
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript" language="javascript">

    function change()
    {
    alert(size[1][0]);

    }

    </script>

    </head>

    <body>
    <script language="javascript">
    var size = new Array();
    var = count;
    for (count = 0; count < 5; count++)
    size[count] = new Array();
    size[0][0] = 600;
    size[0][1] = 400;
    size[1][0] = 300;
    size[1][1] = 400;
    size[2][0] = 300;
    size[2][1] = 400;
    size[3][0] = 600;
    size[3][1] = 400;
    size[4][0] = 300;
    size[4][1] = 400;
    </script>
    <input type="button" value="Click Me" onClick="change()"/>

    </body>
    </html>

    Anything wrong with my coding,any kind support will be apreciated.

    Thanks,
    Srinivas.

  2. #2
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: Javascript function call

    Hi there deekshas,

    and a warm welcome to these forums.

    1. The modern method of coding requires that javascript is removed from the markup.
    2. The attribute language="javascript" is deprecated and should not be used.

    Here is the reworking of your code...
    Code:
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name="language" content="english"> 
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    
    <title>Untitled Document</title>
    
    <script type="text/javascript">
    
    function change() {
       size=[] ;
    
    for(count=0;count<5;count++){
       size[count]=new Array();
     }
       size[0][0]=600;
       size[0][1]=400;
       size[1][0]=300;
       size[1][1]=400;
       size[2][0]=300;
       size[2][1]=400;
       size[3][0]=600;
       size[3][1]=400;
       size[4][0]=300;
       size[4][1]=400;
    
    document.getElementById('button').onclick=function(){
       alert(size[1][0]);
      }
     }
    
    if(window.addEventListener){
       window.addEventListener('load',change,false);
     }
    else { 
    if(window.attachEvent){
       window.attachEvent('onload',change);
      }
     }
    </script>
    
    </head>
    <body>
    
    <div>
     <input id="button" type="button" value="Click Me">
    </div>
    
    </body>
    </html>
    



Tags for this Thread