I have this looping structure:
Code:
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:
Code:
str+="<%=full_formatted_date%></td>"
Heres my Loop:
Code:
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:
Code:
<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'>ID</a></td>" // The Contract ID (e.g. 244)
str+="<td align='left'><a href='#' onclick=\"sortAsc(1,'s')\" title='Sort by Airline'>A/L</a></td>" // The Airline Code (e.g. AF)
str+="<td align='left'><a href='#' onclick=\"sortAsc(2,'s')\" title='Sort by Contract Code'>Contract Code</a></td>" // The Contract Code
str+="<td align='left'><a href='#' onclick=\"sortAsc(3,'s')\" title='Sort by Remark'>Remark</a></td>" // The Remark
str+="<td align='left'><a href='#' onclick=\"sortAsc(5,'i')\" title='Sort by Date Loaded'>Date Loaded</a></td>" // Date Loaded (05-MAR-2005)
str+="<td align='left'><a href='#' onclick=\"sortAsc(6,'i')\" title='Sort by Expiry Date'>Expiry Date</a></td>" // Expiry Date
str+="<td align='left'><a href='#' onclick=\"sortAsc(7,'s')\" title='Sort by Contract Title'>Contract Title</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+=""
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></td>"
str+="<td align='left'>" + arr[f][1] + "</td>"
str+="<td align='left'>" + arr[f][2] + "</td>"
str+="<td align='left'>" + arr[f][3] + "</td>"
str+="<td align='left'>" + arr[f][5] + "</td>"
str+="<td align='left'><div id='hidden' style='visibility:hidden'>" + arr[f][6] + "</div>"
str+="<%=full_formatted_date%></td>"
str+="<td align='left'>" + arr[f][7] + "</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>
www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt