Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function doesn't return a value 3

Status
Not open for further replies.

Mickbw

Programmer
Jul 9, 2001
84
US
I am passing the following function a string value '13-05-2004'. It is supposed to parse out the individual numeric values and see if they are valid month, day, and year values.

Code:
function ParseDate(FormField,DateFormat)
		{
		//DateFormat 1 = mmddyyyy, 2 = yyyymmdd
var cFieldValue =	
document.getElementById(FormField).value;
//alert(cFieldValue);
The alert shows 13-04-2004
Code:
var dtDate_array=	cFieldValue.split("-");
		alert(dtDate_array[0]+" "+dtDate_array[1]+" "+dtDate_array[2]);
The alert shows 13 04 2004
Code:
if(DateFormat = 1)
			//mm-dd-yy format
			{
			alert(parseInt(dtDate_array[0]));
The alert shows 13
Code:
if (parseInt(dtDate_array[0]) < 0 && parseInt(dtDate_array[0]) > 12)
				{alert('Bad Month Passed');
				return false;
				}
The alert doesn't show and no value is returned

What am I doing wrong? Thanks for the help.

Have a nice weekend,



Michael Brennan-White
New Hampshire Treasury Department
 
The alert never fires because a dtDate_array[0] can never be both less than 0 AND greater than 12. Change your && to || and all should once again be right with the world!

Have a good weekend!

--Dave
 
if(DateFormat = 1)
should be

if(DateFormat == 1)

'=' is an assignment operator so it Gives DateFormat a value of 1.

'==' queries whether it is 1.
 

You should also change:

Code:
alert(parseInt(dtDate_array[0]));

to read:

Code:
alert(parseInt(dtDate_array[0], 10));

Hope this helps,
Dan
 
Thanks for all your help,

It is scary that in a small section of code I could make so many errors. Now I can apply your fixes to my entire function.

I feel like I am a pretty good programmer in most errors but Javascript continually has me spinning in a circle. Thanks a lot.



Michael Brennan-White
New Hampshire Treasury Department
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top