  ProtusMose Say hi to your mother for me. Premium join:2001-10-03 Bellevue, NE
·Cox HSI
| [Javascript] Submit button not working.
I created a generic page for school that isn't functioning. The assignment has already been turned in, so I'm not asking for anyone to do my homework. I'm just trying to figure out where I went wrong, since apparently I've got a fundamental knowledge gap somewhere in here that I haven't been able to resolve.
The page is at:
»academic1.bellevue.edu/users/BSW···pay.html
I'm having a hard time getting the function to display the text properly. It's saying the results are NaN. I can't tell if I converted it to a string incorrectly or what. It's kicking it back with:
Employee #1 earned: $NaNEmployee #2 earned: $NaNEmployee #3 earned: $NaN
Here's the JS:
Can someone give me at least a hint at where I should have taken that left turn at Albuquerque?
-- Blogsaus "The same crowd that cheers at your triumphant entry will be the ones that crucify you in the end. Consider this: the very thing that is worth dying for will be the very thing they hate you for - Andrew Schwab |
|
  cowboyro
join:2000-10-11 Shelton, CT 1 edit | var fieldValue=document.getElementById('fieldId').value  document.getElementById() will return the element not the value of the element. |
|
  ProtusMose Say hi to your mother for me. Premium join:2001-10-03 Bellevue, NE
·Cox HSI
| said by cowboyro :var fieldValue=document.getElementById('fieldId') .value :p document.getElementById() will return the element not the value of the element. Thanks for the clarification. That's how I had it originally, but because I misspelled the script name in the html (:O) it wasn't doing anything and I changed it.
I changed it back to:
Now it looks like there is some kind of error in the logic of the write function.
"Employee #1 earned: $0Employee #2 earned: $0Employee #3 earned: $0" -- Blogsaus "The same crowd that cheers at your triumphant entry will be the ones that crucify you in the end. Consider this: the very thing that is worth dying for will be the very thing they hate you for - Andrew Schwab |
|
  JAAulde yum yum yum yum yum Premium,MVM join:2001-05-09 Hagerstown, MD
1 edit | reply to ProtusMose Besides what cowboyro pointed out, which is definitely correct, there are some issues: 1) Do not cheat on line breaks, curly braces, semicolons, etc. It can confuse you or people who read your code, and can cause the parser to do things you're not expecting. 2) Don't try to do so much in one step/line. Break things up for your own readability--mistakes will be a lot easier to find.
Those things in mind, I modified your code to do the following: http://pastie.textmate.org/private/3opk2lrb3ys92qpbyyocpw
This code works as expected for me.
Some issues I did not correct, but should be noted 1) Many concerns are being combined and coupled in one large function. Things should be broken down into separate, modular, flexible methods to take care of separate concerns (data retrieval, validation, calculations, presentation, etc) 2) Your code requires hard changes to add employees, change overtime threshold, etc. After breaking into separate areas of concern, much of this should become "settable" so that you can easily maintain your code. I did partially address this in my changes, but more should be done. 3) You have a whole lot of repetitive logic/calculations. For maintainability and readability, this sort of functionality should be grouped and abstracted so that it is much more easy to work with. Again, I partially addressed that in my edits.
I recognize the above 3 concerns may not be an issue for you in this very small system, but the more you take it into account, the more ready you'll be to continue building on this. You'll also have your head in the right place when a large job comes around.
Edit: moved code to pastie.textmate.org because the code formatter here is so inflexible
-- No eat apple, eat cookie. Apple spoil dinner.
My Development Sandbox | LinkedIn Profile |
|