code doesn't work!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dhaval1993
    New Member
    • Apr 2013
    • 13

    code doesn't work!!

    i wanted to print name which is given by user dynamically.
    that is "myMother.first name".but it does not work any more.please help me solve this.
    Code:
    <body>
    <p>heyy</p>
    First name:<input type="text" id="fname" onclick="callme()">
    <script type="text/javascript">
    <!--
    	
    	function person(firstname)
      	{
    		  this.firstname=firstname;
    		 
      	}
    	
    	function callme()
    	{
    		var n=document.getElementById("fname").value;
    		myMother=new person(n);
    	}
    	 var d=document.getElementById("demo");
    	 document.write("First name is:" +d.innerHTML=myMother.firstname);
    //-->
    </script>
    <p id="demo"></p>
    </body>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    document.write( ) is deleting your page (when used after the initial page load), including all scripts.

    Comment

    • dhaval1993
      New Member
      • Apr 2013
      • 13

      #3
      sorry,i cant get it what you trying to say.please elaborat.
      Thank you.

      Comment

      • dhaval1993
        New Member
        • Apr 2013
        • 13

        #4
        okay i just edit my code.In that i remove document.write( ).
        but still it has no effect on output!!!

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          sorry,i cant get it what you trying to say
          I said that document.write( ) erases your page (in the browser, not on the server, of course), it’s as simple as that.

          but still it has no effect on output!!!
          post the new code.

          Comment

          • dhaval1993
            New Member
            • Apr 2013
            • 13

            #6
            Code:
            <p>heyy</p>
            First name:<input type="text" id="fname" onclick="callme()">
            <script type="text/javascript">
            
            	
            	function person(firstname)
              	{
            		  this.firstname=firstname;
            		 
              	}
            	
            	function callme()
            	{
            		var n=document.getElementById("fname").value;
            		myMother=new person(n);
            	}
            	 var d=document.getElementById("demo");
            	 d.innerHTML=myMother.firstname;
            	 
            </script>
            <p id="demo"></p>
            </body>

            Comment

            • dhaval1993
              New Member
              • Apr 2013
              • 13

              #7
              function person(firstnam e)
              this is called or not!
              as there is no output on my browser!

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                anything in the Error Console?

                Comment

                Working...