By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

code doesn't work!!

P: 13
i wanted to print name which is given by user dynamically.
that is "myMother.firstname".but it does not work any more.please help me solve this.
Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <p>heyy</p>
  3. First name:<input type="text" id="fname" onclick="callme()">
  4. <script type="text/javascript">
  5. <!--
  6.  
  7.     function person(firstname)
  8.       {
  9.           this.firstname=firstname;
  10.  
  11.       }
  12.  
  13.     function callme()
  14.     {
  15.         var n=document.getElementById("fname").value;
  16.         myMother=new person(n);
  17.     }
  18.      var d=document.getElementById("demo");
  19.      document.write("First name is:" +d.innerHTML=myMother.firstname);
  20. //-->
  21. </script>
  22. <p id="demo"></p>
  23. </body>
  24.  
Jul 21 '13 #1
Share this Question
Share on Google+
7 Replies


Dormilich
Expert Mod 5K+
P: 8,639
document.write() is deleting your page (when used after the initial page load), including all scripts.
Jul 21 '13 #2

P: 13
sorry,i cant get it what you trying to say.please elaborat.
Thank you.
Jul 21 '13 #3

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

Dormilich
Expert Mod 5K+
P: 8,639
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.
Jul 21 '13 #5

P: 13
Expand|Select|Wrap|Line Numbers
  1. <p>heyy</p>
  2. First name:<input type="text" id="fname" onclick="callme()">
  3. <script type="text/javascript">
  4.  
  5.  
  6.     function person(firstname)
  7.       {
  8.           this.firstname=firstname;
  9.  
  10.       }
  11.  
  12.     function callme()
  13.     {
  14.         var n=document.getElementById("fname").value;
  15.         myMother=new person(n);
  16.     }
  17.      var d=document.getElementById("demo");
  18.      d.innerHTML=myMother.firstname;
  19.  
  20. </script>
  21. <p id="demo"></p>
  22. </body>
  23.  
Jul 21 '13 #6

P: 13
function person(firstname)
this is called or not!
as there is no output on my browser!
Jul 21 '13 #7

Dormilich
Expert Mod 5K+
P: 8,639
anything in the Error Console?
Jul 21 '13 #8

Post your reply

Sign in to post your reply or Sign up for a free account.