Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 7th, 2005, 6:54 AM   #1
crmpicco
Newbie
 
Join Date: Feb 2005
Posts: 13
Rep Power: 0 crmpicco is on a distinguished road
ASP/JavasCript problem

I have this looping structure:
while not rs.eof
.....

rs.movenext
counter=counter+1
wend

Inside the loop full_date_expiry_newdate is created with around 250 different values.

I need to put all those values in a ASP/Javascript array to pull it off here in my JavaScript, which is underneath my ASP:

str+="<font face='verdana' size='1'><%=full_formatted_date%></font></td>"

Heres my Loop:
	while not rs.eof
		
		'''''''''''''''''''''''''''''''''''''''''''''
		' Date Created								'
		'''''''''''''''''''''''''''''''''''''''''''''
		
		org_date = rs("date_cr")
		if rs("date_cr") = "" then
		create_newdate = false
		end if
		
		the_year = right(org_date,4)

		iSlashPos = instr(org_date,"/")
		
		the_month = left(org_date, islashpos - 1)
		
		org_date_len = len(org_date)
		
		if org_date_len = 8 then
			the_day = mid(org_date,3,1)
		end if

		if org_date_len = 9 then
		iBackSlashPos = instr(org_date,"/") 

		if iBackSlashPos = 2 then
			the_day = mid(org_date,3,2)
		elseif iBackSlashPos = 3 then
			the_day = mid(org_date,4,1)
		end if
		end if

		if org_date_len = 10 then
			the_day = mid(org_date,4,2)
		end if
		
		if the_year <> "" then
		full_formatted_date = the_day & "-" & setshortdate(the_month) & "-" & the_year 
		end if

		if len(the_day) = 1 then
		the_day = "0"&the_day
		end if

		if len(the_month) = 1 then
		the_month = "0"&the_month
		end if
		
		full_date_cr_newdate = the_day & the_month & the_year
		full_date_created_newdate = the_year & the_month & the_day
		
		''''''''''''''''''''''''''''''''''''
		' Expiry Date				       '	
		''''''''''''''''''''''''''''''''''''
		
		org_date_exp = rs("date_exp")
		if rs("date_exp") = "" then
		create_newdate_exp = false
		end if
		
		the_year_exp = right(org_date_exp,4)

		iSlashPos_exp = instr(org_date_exp,"/")
		
		the_month_exp = left(org_date_exp, islashpos_exp - 1)
		
		org_date_len_exp = len(org_date_exp)
		
		if org_date_len_exp = 8 then
			the_day_exp = mid(org_date_exp,3,1)
		end if

		if org_date_len_exp = 9 then
		iBackSlashPos_exp = instr(org_date_exp,"/") 
		if iBackSlashPos_exp = 2 then
			the_day_exp = mid(org_date_exp,3,2)
		elseif iBackSlashPos_exp = 3 then
			the_day_exp = mid(org_date_exp,4,1)
		end if
		end if

		if org_date_len_exp = 10 then
			the_day_exp = mid(org_date_exp,4,2)
		end if
		
		if the_year_exp <> "" then
		full_formatted_date_exp = the_day_exp & "-" & setshortdate(the_month_exp) & "-" & the_year_exp 
		end if
		
		full_date_expiry_newdate = the_year_exp & the_month_exp & the_day_exp
		
		set rsupdate=con.execute("update contract set date_cr_newdate = '"& full_date_created_newdate &"' where contract_id = '" & rs("contract_id") & "'")
		set rsupdateexp=con.execute("update contract set date_exp_newdate = '"& full_date_expiry_newdate &"' where contract_id = '" & rs("contract_id") & "'")
		
				arr(counter,0)=rs("contract_id")
				arr(counter,1)=rs("air_cds")
				arr(counter,2)=rs("contract_code")
				arr(counter,3)=rs("remark")
				arr(counter,4)=rs("status")
				arr(counter,5)=full_date_created_newdate ' rs("date_cr") 'full_formatted_date ' 
				arr(counter,6)=full_date_expiry_newdate 'full_formatted_date_exp ' 
				arr(counter,7)=rs("contract_title")
		
	rs.movenext
	counter=counter+1
	wend

and my JS:
<script language="Javascript">
<!--
var a=new Array();
var arr=new Array();
var seq=new Array();

str="<%=str%>"

function load()
{
	a=str.split("~");
	for(i=0;i<a.length-1;i++)
	{
		arr[i]=a[i].split("^");
	}	
	sortAsc(6,'d');
}
function sortAsc(sub,dtype)
{
	
	var tmpArr=new Array();
	var arrQa=new Array();
	for(i=0;i<arr.length;i++)
	{
		tmpArr[i]=arr[i][sub];
		arrQa[i]=arr[i][1];
		seq[i]=i;
	}
	
	var tmp;
	var tmp1;
	for(j=0;j<tmpArr.length;j++)
	{
		for(k=0;k<tmpArr.length-1;k++)
		{
		///////////////////////////////////////
		// SORT AN INTEGER					 //
		///////////////////////////////////////
		
			if(dtype=='i')
			{
				if(parseInt(tmpArr[k])>parseInt(tmpArr[k+1]))
				{
					tmp=tmpArr[k+1];
					tmpArr[k+1]=tmpArr[k];
					tmpArr[k]=tmp;
					
					tmpQa=arrQa[k+1];
					arrQa[k+1]=arrQa[k];
					arrQa[k]=tmpQa;
					
					tmp1=seq[k+1];
					seq[k+1]=seq[k];
					seq[k]=tmp1;	
				}
				else if(parseInt(tmpArr[k])==parseInt(tmpArr[k+1]))
				{
					if(arrQa[k]>arrQa[k+1])
					{
						tmp=tmpArr[k+1];
						tmpArr[k+1]=tmpArr[k];
						tmpArr[k]=tmp;
					
						tmpQa=arrQa[k+1];
						arrQa[k+1]=arrQa[k];
						arrQa[k]=tmpQa;
					
						tmp1=seq[k+1];
						seq[k+1]=seq[k];
						seq[k]=tmp1;	
					}
				}
			}
			
		///////////////////////////////////////
		// SORT AN STRING					 //
		///////////////////////////////////////

			if(dtype=='s')
			{
				if(tmpArr[k]>tmpArr[k+1])
				{
					tmp=tmpArr[k+1];
					tmpArr[k+1]=tmpArr[k];
					tmpArr[k]=tmp;
									
					tmpQa=arrQa[k+1];
					arrQa[k+1]=arrQa[k];
					arrQa[k]=tmpQa;
					
					tmp1=seq[k+1];
					seq[k+1]=seq[k];
					seq[k]=tmp1;	
				}
				else if(tmpArr[k]==tmpArr[k+1])
				{
					if(arrQa[k]>arrQa[k+1])
					{
						tmp=tmpArr[k+1];
						tmpArr[k+1]=tmpArr[k];
						tmpArr[k]=tmp;
										
						tmpQa=arrQa[k+1];
						arrQa[k+1]=arrQa[k];
						arrQa[k]=tmpQa;
											
						tmp1=seq[k+1];
						seq[k+1]=seq[k];
						seq[k]=tmp1;	
					}
				}
				
			}

		///////////////////////////////////////
		// SORT AN DATE						 //
		///////////////////////////////////////

			if(dtype=='d')
			{
			    var d1=new Date(tmpArr[k]);
			    var d2=new Date(tmpArr[k+1]);
			    
			    if(d1>d2)
				{
					tmp=tmpArr[k+1];
					tmpArr[k+1]=tmpArr[k];
					tmpArr[k]=tmp;
					
					tmpQa=arrQa[k+1];
					arrQa[k+1]=arrQa[k];
					arrQa[k]=tmpQa;
					
					tmp1=seq[k+1];
					seq[k+1]=seq[k];
					seq[k]=tmp1;	
				}
				else if(d1.valueOf()==d2.valueOf())
				{
					if(arrQa[k]>arrQa[k+1])
					{
						tmp=tmpArr[k+1];
						tmpArr[k+1]=tmpArr[k];
						tmpArr[k]=tmp;
					
						tmpQa=arrQa[k+1];
						arrQa[k+1]=arrQa[k];
						arrQa[k]=tmpQa;
					
						tmp1=seq[k+1];
						seq[k+1]=seq[k];
						seq[k]=tmp1;
					}
				}
			}
			
		}
	}
	// Proceed to build the HTML table
	maketable();
}
///////////////////////////
// sortAsc(0,i) INTEGER  //
// sortAsc(0,s) STRING   //
// sortAsc(0,d) DATE	 //
///////////////////////////
function maketable(edit)
{
str="<table width='100%' cellspacing='1' cellpadding='2' border='1' align='center'>"
str+="<tr bgcolor='#ececec'bordercolor='#cccccc'>"
str+="<td align='left'><a href='#' onclick=\"sortAsc(0,'i')\" title='Sort by ID'><font face='verdana' size=1>ID</font></a></td>"  // The Contract ID (e.g. 244)
str+="<td align='left'><a href='#' onclick=\"sortAsc(1,'s')\" title='Sort by Airline'><font face='verdana' size=1>A/L</font></a></td>" // The Airline Code (e.g. AF)
str+="<td align='left'><a href='#' onclick=\"sortAsc(2,'s')\" title='Sort by Contract Code'><font face='verdana' size=1>Contract Code</font></a></td>" // The Contract Code
str+="<td align='left'><a href='#' onclick=\"sortAsc(3,'s')\" title='Sort by Remark'><font face='verdana' size=1>Remark</font></a></td>" // The Remark
str+="<td align='left'><a href='#' onclick=\"sortAsc(5,'i')\" title='Sort by Date Loaded'><font face='verdana' size=1>Date Loaded</font></a></td>" // Date Loaded (05-MAR-2005)
str+="<td align='left'><a href='#' onclick=\"sortAsc(6,'i')\" title='Sort by Expiry Date'><font face='verdana' size=1>Expiry Date</font></a></td>" // Expiry Date 
str+="<td align='left'><a href='#' onclick=\"sortAsc(7,'s')\" title='Sort by Contract Title'><font face='verdana' size=1>Contract Title</font></a></td>" // The Contract Title
str+="</tr>"

	var curdes="<%=curdes%>";
	for(i=0;i<seq.length;i++)
	{
		f=seq[i];
						
		str+="<tr bgcolor='#ececec' bordercolor='#cccccc'>" 
		str+="<td align='left'>"
		str+="<font face='verdana' size='1'>"
		str+="<a href='display_fare_search2.asp?air_cds="+ arr[f][1] +"&contract_id="+ arr[f][0] +"&contract_title="+arr[f][7]+"'>" + arr[f][0] + "</a></font></td>"
		str+="<td align='left'><font face='verdana' size='1'>" + arr[f][1] + "</font></td>"
		str+="<td align='left'><font face='verdana' size='1'>" + arr[f][2] + "</font></td>"
		str+="<td align='left'><font face='verdana' size='1'>" + arr[f][3] + "</font></td>"
		str+="<td align='left'><font face='verdana' size='1'>" + arr[f][5] + "</font></td>"
		str+="<td align='left'><font face='verdana' size='1'><div id='hidden' style='visibility:hidden'>" + arr[f][6] + "</div></font>"
		str+="<font face='verdana' size='1'><%=full_formatted_date%></font></td>"
		str+="<td align='left'><font face='verdana' size='1'>" + arr[f][7] + "</font></td>"
		str+="</tr>"
				
		///////////////////////////////////////////
		// Array Values							 //
		// alert (arr[f][0]) Contract ID		 //
		// alert (arr[f][1]) Airline Code		 //
		// alert (arr[f][2]) Contract Code		 //
		// alert (arr[f][3]) Remark				 //
		// alert (arr[f][4]) Status 			 //
		// alert (arr[f][5])// Date Loaded		 //
		// alert (arr[f][6]) Date Expiry		 //
		// alert (arr[f][7]) Contract Title		 //
		///////////////////////////////////////////
	}
	str+="<tr><td></td></tr></table>"
	document.all.tt.innerHTML=str;
	
}
//-->
</script>
crmpicco is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:19 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC