www.webdeveloper.com
Results 1 to 5 of 5

Thread: help in this code

  1. #1
    Join Date
    Apr 2011
    Posts
    8

    Unhappy help in this code

    Code:
    <html>
      <head>
        <title>iRock - The Virtual Pet Rock</title>
         <script type = "text/javascript">
    	 function touchRock(){
    	 var userName=promt("What is your name?","Enter your name here.");
    	 if (userName){
    	 alert("It is good to meet you," + userName + ".");
    	 document.getElementById("rockImg").src= "rock_happy.png";
    	 }
    	 }
    	 </script>
      </head>
    
      <body onload="alert('Hello, I am your pet rock.');">
        <div style="margin-top:100px; text-align:center">
          <img id="rockImg" src="rock.png" alt="iRock" style="cursor:pointer" onclick="touchRock();" />
        </div>
      </body>
    </html>
    THIS CODE IS NOT WORKING AS IT SHOULD , ITS NOT JUMPING TO THE TOUCHROCK FUNCTION... PLS HELP ..
    Last edited by Kor; 04-07-2011 at 03:43 AM. Reason: wrap the code [code][/code]

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/javascript">
    function touchRock(){
    var userName=prompt("What is your name?","Enter your name here.");
    if(userName.length>0){
    alert("It is good to meet you," + userName + ".");
    document.getElementById("rockImg").src= "rock_happy.png";
    }
    }
    </script>
    </head>
    <body>
    <div style="margin-top:100px; text-align:center">
    <img id="rockImg" src="rock.png" alt="iRock" style="cursor:pointer" onclick="touchRock();" />
    </div>
    </body>
    </html>

  3. #3
    Join Date
    Apr 2011
    Posts
    8
    Quote Originally Posted by Kor View Post
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/javascript">
    function touchRock(){
    var userName=prompt("What is your name?","Enter your name here.");
    if(userName.length>0){
    alert("It is good to meet you," + userName + ".");
    document.getElementById("rockImg").src= "rock_happy.png";
    }
    }
    </script>
    </head>
    <body>
    <div style="margin-top:100px; text-align:center">
    <img id="rockImg" src="rock.png" alt="iRock" style="cursor:pointer" onclick="touchRock();" />
    </div>
    </body>
    </html>
    i am not able to understand , where is the fault in my code..

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by learner420 View Post
    i am not able to understand , where is the fault in my code..
    See the blue in my code. By short:

    1. Your document had no doctype
    2. the method is prompt() not promt()
    3. the variable userName is always defined (in the worst case it has a an empty string as value), thus if(userName) has no sense, as userName will be always evaluated as a true Boolean

  5. #5
    Join Date
    Apr 2011
    Posts
    8
    Quote Originally Posted by Kor View Post
    See the blue in my code. By short:

    1. Your document had no doctype
    2. the method is prompt() not promt()
    3. the variable userName is always defined (in the worst case it has a an empty string as value), thus if(userName) has no sense, as userName will be always evaluated as a true Boolean
    thanks kor... have a nice day bro..

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