Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NaN

 
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Still the same issue....

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Any errors in the JavaScript console?
 
    Bookmark Topic Watch Topic
  • New Topic