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

how we can call methods which are used in called function

P: 1
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function muloperator()
  3. {
  4.  var val1 = parseInt(document.getElementById("txt1").value);
  5.         var val2 = parseInt(document.getElementById("txt2").value); 
  6.        var ans=document.getElementById("demo")
  7.  
  8. }
  9.  
  10.   sum()
  11.  {
  12.       ans.value = val1+ val2;
  13. }
  14. minus()
  15. {
  16. ans.value = val1 - val2;
  17. }
  18. mul()
  19. {
  20. ans.value = val1+ val2;
  21. }
  22. div()
  23. {
  24. ans.value = val1+ val2;
  25. }
  26.     </script>
  27. <body>
  28. <fieldset>
  29. <form>
  30.     <input type="text" id="txt1" name="text1">
  31.     <input type="text" id="txt2" name="text2">
  32. <input type="button" value="+" name="submit"><input type="button" value="-" name="submit">
  33. <input type="button" value="*" name="submit">
  34. <input type="button" value="/" name="submit">
  35. <input type="text" id="demo" name="demo" onclick="muloperator()"/>
Jul 7 '16 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
your functions don't make sense. from a sum() function anyone would expect that you pass in two values and get back their sum.

next, assigning the result is obviously not the responsibility of a calculation function.

and then there is the issue that the buttons do nothing at all.
Jul 7 '16 #2

Post your reply

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