473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

how we can call methods which are used in called function

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
3 2957
Dormilich
8,658 Expert Mod 8TB
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
Sherin
77 64KB
Expand|Select|Wrap|Line Numbers
  1. function Product(name, price) {
  2.   this.name = name;
  3.   this.price = price;
  4. }
  5.  
  6. function Food(name, price) {
  7.   Product.call(this, name, price);
  8.   this.category = 'food';
  9. }
  10.  
  11. console.log(new Food('cheese', 5).name);
  12.  
May 6 '20 #3
For a start, let’s teach the user to say hello:

Expand|Select|Wrap|Line Numbers
  1. let user = {
  2.   name: "John",
  3.   age: 30
  4. };
  5.  
  6. user.sayHi = function() {
  7.   alert("Hello!");
  8. };
  9.  
  10. user.sayHi(); // Hello!
Here we’ve just used a Function Expression to create the function and assign it to the property user.sayHi of the object.

Then we can call it. The user can now speak!

A function that is the property of an object is called its method.

So, here we’ve got a method sayHi of the object user.

Of course, we could use a pre-declared function as a method, like this:
Expand|Select|Wrap|Line Numbers
  1. let user = {
  2.   // ...
  3. };
  4.  
  5. // first, declare
  6. function sayHi() {
  7.   alert("Hello!");
  8. };
  9.  
  10. // then add as a method
  11. user.sayHi = sayHi;
  12.  
  13. user.sayHi(); // Hello!
May 9 '20 #4

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

Similar topics

6
by: aling | last post by:
How do you call a regular member function from a static member function? Any idea?
3
by: David N | last post by:
Hi All, I just wonder if in C#, I can develop a user defined control that can call its parent function which is not yet developed. For example, how do I make my user control call a...
3
by: Taptu¶ | last post by:
Hi I have a problem. I have a function : void for3::drzewo() { m_lista.DeleteAllItems(); m_li.GetImageList();
0
by: Eric Richardson | last post by:
I have a web service method that asyhcronously calls a long-running function, using BeginInvoke, passing a callback delegate. So the client calls the web method, which makes an asynchronous call...
5
by: rbfish | last post by:
Hi, How can I call a virtual base function with variable parameters? like, class base { public: int printf(const char *fmt, ...) { // do anything here.
5
by: loudwinston | last post by:
Hello, I'm encountering a strange error with PDO. The server is FreeBSD 4.4, PHP 5.1.2, mySQL 4.0.20 with 4.1.18 client libs. I have the following code (usernames and passwords changed to...
6
by: Jahangir | last post by:
Hello All, In my project I am using php calendar. I have used it locally it is working perfactly, but when I upload it on remote server it gives Fatal error: Call to a member function on a...
28
by: ravi | last post by:
Hello everybody, I am writing a small application which does some work before the user main function starts execution. I am trying to #define the main function. But the problem is that,
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
1
by: chris6565 | last post by:
In my program I am calling a function using a reference to a structure: struct stringy { char* str; int ct; } void set(reference to stringy, c-string) Inside the function I want to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.