Bookmark Topic Watch Topic
  • New Topic

NaN  RSS feed

 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Report post to moderator
I can't seem to get my function right.....It's a tuition calculator. At this point the residency and semesters don't matter. It's just credits * credit cost, but it keeps returning NaN.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Your function expects two parameters yet you call it with none.
 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Bear Bibeault wrote:Your function expects two parameters yet you call it with none.


Are you referring to the arguments in the function?  Should it be empty?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
No. Your function is defined as:
which expects two arguments which it will multiply. If you pass nothing, it will multiply undefined by undefined and the result is clearly not a number (expressed as NaN).
 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Bear Bibeault wrote:No. Your function is defined as:
which expects two arguments which it will multiply. If you pass nothing, it will multiply undefined by undefined and the result is clearly not a number (expressed as NaN).


Sorry I'm just a little confused by what you mean.  In my mind, I set the variables as numbers.  I appreciate your help, but I don't exactly know what you mean.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
In the following code, where do you pass two numbers?

You pass nothing.

What is it you want to be multiplying together? Those values need to be passed to the function.
 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Bear Bibeault wrote:In the following code, where do you pass two numbers?

You pass nothing.

What is it you want to be multiplying together? Those values need to be passed to the function.


Oh, I didn't realize you meant down there.  So if I put the variables in the onchange, I will be alright?
 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Still the same issue....

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
No, those variables are undefined in the onchange handler.

It seems you are just guessing at this point; you need to ask yourself what values you want to actually pass into the function. When onchange triggers, what is it you actually want to have happen?
 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Bear Bibeault wrote:No, those variables are undefined in the onchange handler.

It seems you are just guessing at this point; you need to ask yourself what values you want to actually pass into the function. When onchange triggers, what is it you actually want to have happen?


Not guessing just trying to problem solve.  I did some more research and made just changes, but am still at an I'm at an impasse.

 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Bear Bibeault wrote:No, those variables are undefined in the onchange handler.

It seems you are just guessing at this point; you need to ask yourself what values you want to actually pass into the function. When onchange triggers, what is it you actually want to have happen?


Trying getElementByID.....still nothing...ugh

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
In order to use getElementById, the element must have an id. The name is not the same as an id. (name is only used for form submission, so you don't really even need one here.)

There is also getElementsByName if you want to continue to use names.
 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Bear Bibeault wrote:In order to use getElementById, the element must have an id. The name is not the same as an id. (name is only used for form submission, so you don't really even need one here.)

There is also getElementsByName if you want to continue to use names.




Yes, I remember that now, but nothing is happening when I hit the button.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Any errors in the JavaScript console?
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!