MJ
asked on
NaN error on subtraction of selectedIndex
Why would the below code return NaN:
alert("DOES NOT WORK - RETURNS NaN:"+document.pollform.mo nth[docume nt.pollfor m.month.se lectedInde x].value - 1);
if I remove the subtraction it works fine???
alert("WORKS:"+document.po llform.mon th[documen t.pollform .month.sel ectedIndex ].value - 1);
alert("DOES NOT WORK - RETURNS NaN:"+document.pollform.mo
if I remove the subtraction it works fine???
alert("WORKS:"+document.po
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Check this:
alert("WORKS:"+(document.p ollform.mo nth.value- 1))
One question for explanation: does JavaScript evaluate the statement expression from left to right or right to left?
And if it is from left to right, what number should yield this: ""DOES NOT WORK - RETURNS NaN: 9"-1;
alert("WORKS:"+(document.p
One question for explanation: does JavaScript evaluate the statement expression from left to right or right to left?
And if it is from left to right, what number should yield this: ""DOES NOT WORK - RETURNS NaN: 9"-1;
try using the way roonaan has suggested.
i think alert tries to evaluate the msg passed to it.
i think alert tries to evaluate the msg passed to it.
Your var age is NOT an Object of type: Date
ASKER
It is I just didn't post the whole code!
var age = new Date();
var age = new Date();
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found the issue. it was on the getting of the dates
age.getMonth vs age.getMonth()
age.getMonth vs age.getMonth()
ASKER
I should have stated my question better! :(
You can ask for delete for this question here: http:/Community_Support/askQuestion.jsp
ASKER
age.setMonth(document.poll