Jump to content

Passing arrays between php files


Adam Brave

Recommended Posts

Just one last question a little bit offtopic. I have this two lines of code:

month = document.calForm.selMonth.options[document.calForm.selMonth.selectedIndex].value;month += 1;

What I expected that should happen was the variable "month" to be incremented, but what really happen is that if "month" is equal 5 on the end of the first line then in the second line it will result "51" . The instruction "month += 1" does not do a numerical calculation, instead, it joins "1" to the previous value of the variable. How can I change this?

Link to comment
Share on other sites

Unfortunately, the + operator works on strings and numbers differently. In your case, it thinks it's operating on strings, because the value of a form control is always a string. Try this:

month = parseInt(month) + 1;

There are tricks you can use to save a few characters in that code, but this way makes your intentions 100% clear.

Edited by Deirdre's Dad
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...