Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 7th, 2005, 06:54 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default Array Problem

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
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array Problem...Can anyone help?? :( Shuchik Classic ASP Basics 1 September 25th, 2007 05:21 AM
Array problem Ivanchan Excel VBA 2 July 24th, 2007 08:28 PM
Array Problem monika.vasvani ASP.NET 1.0 and 1.1 Professional 3 September 13th, 2006 05:56 AM
Array problem NEO1976 Javascript 0 August 3rd, 2006 03:55 AM
Array Problem hayley Classic ASP Basics 4 February 2nd, 2005 12:42 AM



All times are GMT -4. The time now is 07:43 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.