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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

substring

Status
Not open for further replies.

cat5ive

MIS
Dec 3, 2004
184
US
Hi all,

I want to see the value of first 2 characters of variable ctlDuedate but there's seem to be something wrong with my substring statement because the program just run thru document.end without display the value to me.
Code:
function check_input()
	    {  	       
		   	   
		   var ctlDuedate = document.f1.newduedate;
		   var str = "";  	
		   
		   str = ctlDuedate.substring(0,2);
		   document.write(str.value);
		   document.end();
if I remove line
str = ctlDuedate.substring(0,2);
and change write line to
document.write(ctlDuedate.value);
then it stop and show the value correctly, the value shown as 08/21/08.

Please help. Thanks in advance

 
>var ctlDuedate = document.f1.newduedate;
[tt]var ctlDuedate = document.f1.newduedate[red].value[/red];[/tt]

>document.write(str.value);
[tt]document.write(str);[/tt]

ps: document.write(), document.end() seem to have dubious sense in most context where "checking input" has a sense.
 
thank you, tsuji.

I'm able to chop the value now.
This time I try to compare the 2 values. If first date(cymd) is less than 2nd date(ctlCutoff) then I want to pop up the alert message. From my coding below, the message is always pop up no matter if both value are equal, 1st value is more, or 1st value is less.

Code:
                 var ctlCutoff = document.f1.hdcutoff.value;		   
		   var str = ctlDuedate.value;
		   var cymd = "";
		   var year = "";
		   var mon = "";
		   var day = "";
                   year = str.substr(6,2);
		   mon = str.substr(0,2);
		   day = str.substr(3,2);
                   cymd = "20" + year + mon + day;
			
			if (cymd < ctlCutoff);
			{
		     alert ("error!");			 
  		     return false; 
		    }
I test with both value equal 20080826 and did the debug. Both value show 20080826.

Thanks
 
Never mind, found the bug (if (cymd < ctlCutoff);).


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top