Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,093
    Thanks
    15
    Thanked 1 Time in 1 Post

    Angry sort with javascript

    Looking at this javascript, is the table that is built already sorted?

    I am trying to sort the table with my MySQL hit (which the table gets its data from) into newest record first, but i think it has already been sorted by the javascript when it is built.

    Heres my ASP MySQL Hit (this works fine in MySQL Control Center):

    Set rs=con.execute("select * from trip_master where agencyid = '"&agencyid&"' and newdate > '" &new_date& "' and regular_trip <> 'Cancelled' order by pri_key desc limit "&vara&",50")

    Heres my Javascript:

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

    str="<%=str%>"
    tablecolour="<%=tablecolour%>"
    trcolour1="<%=trcolour1%>"

    function searchmytrip(df)
    {
    searchname=df.searchname.value;
    searchagent=df.searchagent.value;
    document.form.action = "/beaver/asp/mytrip.asp?searchagent=" + searchagent + "&searchname=" + searchname;
    document.form.submit();
    }
    function searchagain(df)
    {
    searchname=df.searchname.value;
    searchagent=df.searchagent.value;
    document.searchform.action = "/beaver/asp/mytrip.asp?searchagent=" + searchagent + "&searchname=" + searchname;
    document.searchform.submit();
    }
    function winopen(temp)
    {
    temp="Cryptic.asp?1A=RT" + temp
    oCryp = window.open(temp,'Cryptic','width=700,height=450,scrollbars=yes,resizable=yes,top=50,left=50,menubar =no,status=no');
    }


    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++)
    {

    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;
    }
    }
    }

    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;
    }
    }

    }


    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;
    }
    }
    }

    }
    }
    maketable();
    }

    function maketable(edit)
    {
    str="<table width=700 cellspacing=1 cellpadding=2 border=1 align='center'><tr bgcolor='#ececec'bordercolor='#cccccc'><td align='left'><a href='#' onclick=\"sortAsc(0,'s')\" title='Click here to sort by Name'><font face='verdana' size=1 color=blue>Name</font></a></td><td width='10%' align=center><a href='#' onclick=\"sortAsc(10,'s')\" title='Click here to sort by Trip Status'><font face='verdana' size=1 color=blue>Status</font></a></td><td align='center'><a href='#' onclick=\"sortAsc(1,'s')\" title='Click here to sort by Booking No.'><font face='verdana' size=1 color=blue>Booking No.</font></a></td><td align='center'><a href='#' onclick=\"sortAsc(2,'d')\" title='Click here to sort by Departure Date'><font face='verdana' size=1 color=blue>Departure Date</font></a></td><td align='center'><a href='#' onclick=\"sortAsc(3,'s')\" title='Click here to sort by Itinerary'><font face='verdana' size=1 color=blue>Itinerary</font></a></td><td align='center'><a href='#' onclick=\"sortAsc(6,'d')\" title='Click here to sort by Booking Date'><font face='verdana' size=1 color=blue>Booking Date</font></a></td></tr>"

    var curdes="<%=curdes%>";
    for(i=0;i<seq.length;i++)
    {
    f=seq[i];
    regsel="";
    norsel="";
    optsel="";
    trasel="";
    buttval="";
    callfunc="";
    stxt="";
    saux="";
    if(arr[f][12]!="")
    {
    saux+=arr[f][12].toUpperCase( );
    }
    if(arr[f][13]!="")
    {
    saux+=".";
    saux+=arr[f][13].toUpperCase( );
    }

    if(arr[f][10].toUpperCase( )=="REPEAT")
    {
    regsel="selected";
    stxt="Repeat";
    }
    else if(arr[f][10].toUpperCase( )=="CANCELLED")
    {
    trasel="selected";
    stxt="<font color=red>Cancelled</font>";
    }
    else if(arr[f][10].toUpperCase( )=="TRASH")
    {
    trasel="selected";
    stxt="Trash";
    }
    else if(arr[f][10].toUpperCase( )=="OPTION")

    {
    optsel="selected";
    stxt="Option";
    }
    else
    {
    norsel="selected";
    stxt="Confirmed";
    }

    if(edit==true)
    {
    txvis="hidden";
    txpos="absolute"
    opvis="visible";
    oppos="";
    buttval="Update";
    callfunc="update_regtrip()";
    }
    else
    {
    txvis="visible";
    txpos="";
    opvis="hidden";
    oppos="absolute";
    buttval="Edit";
    callfunc="maketable(true)";
    }
    statustxt="<div style='visibility:" + txvis + ";position:" + txpos + "'><font face='verdana' size='1'>" + stxt +"</font></div>"
    statustxt+="<div style='visibility:" + opvis + ";position:" + oppos + "'><input type='hidden' name='trip" + i + "' value='" + arr[f][1] + "' ><select name='tripstat" + i + "'><option value='Repeat'" + regsel + ">Repeat</option><option value='Confirmed' " + norsel + ">Confirmed</option><option value='Option' " + optsel + ">Option</option><option value='Trash' " + trasel + ">Trash</option></select></div>"

    str+="<tr bgcolor='#ececec' bordercolor='#cccccc'>"
    // str+="<td align='center'>" + statustxt + "</td><td align='left'><font face='verdana' size='1'>" + arr[f][0] + "</font></td>"+"<td align='left'><a href='mytrip1.asp?tripid=" + arr[f][11] + "&pnrno="+ arr[f][1] + "&totalfare="+ arr[f][7] + " " + curdes +"'><font face='verdana' size='1' color='blue'>1A/" + arr[f][1] + "</font></a></td>"+"<td align='center'><font face='verdana' size='1'>" + arr[f] + "</font></td>"+" <td align='center'><font face='verdana' size='1'>" + arr[f][3] + "</font></td>"+"<td align='center'><font face='verdana' size='1'>" + arr[f][4] + "</font></td>"+"<td align='right'><font face='verdana' size='1'>" + arr[f][7] + "</font></td>"+"<td align='center'><font face='verdana' size='1'>" + arr[f][9] + "</font></td>"+"<td align='center'><font face='verdana' size='1'>" + saux + "</font></td>"
    str+="<td align='left'><font face='verdana' size='1'>" + arr[f][0] + "</font></td>"+"<td align='center'>" + statustxt + "</td>"+"<td align='center'><font face='verdana' size='1' color='blue'><a href='mytrip_new.asp?pnrno="+ arr[f][1] +"'>" + arr[f][1] + "</a></font></td>"+"<td align='center'><font face='verdana' size='1'>" + arr[f] + "</font></td>"+"<td align='center'><font face='verdana' size='1'>" + arr[f][3] + "</font></td>"+"<td align='center'><font face='verdana' size='1'>" + arr[f][9] + "</font></td>"
    str+="</tr>"
    }
    str+="<tr><td></td></tr></table>"
    document.all.tt.innerHTML=str;

    }
    function update_regtrip()
    {
    document.regform.submit();
    return true;
    }
    //-->
    </script>

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Come on, crmpicco... haven't you learned to use [code] tags yet?
    *this message will self destruct in n-seconds*

  • #3
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,093
    Thanks
    15
    Thanked 1 Time in 1 Post
    Code:
    <script language="Javascript">
    <!--
    var a=new Array();
    var arr=new Array();
    var seq=new Array();
    
    str="<%=str%>"
    tablecolour="<%=tablecolour%>"
    trcolour1="<%=trcolour1%>"
    
    function searchmytrip(df)
    {
    searchname=df.searchname.value;
    searchagent=df.searchagent.value;
    document.form.action = "/beaver/asp/mytrip.asp?searchagent=" + searchagent + "&searchname=" + searchname;
    document.form.submit();
    }
    function searchagain(df)
    {
    searchname=df.searchname.value;
    searchagent=df.searchagent.value;
    document.searchform.action = "/beaver/asp/mytrip.asp?searchagent=" + searchagent + "&searchname=" + searchname;
    document.searchform.submit();
    }
    function winopen(temp)
    {
    temp="Cryptic.asp?1A=RT" + temp
    oCryp = window.open(temp,'Cryptic','width=700,height=450,scrollbars=yes,resizable=yes,top=50,left=50,menubar=no,sta tus=no');
    }
    
    
    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++)
    {
    
    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; 
    }
    }
    }
    
    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; 
    }
    }
    
    }
    
    
    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;
    }
    }
    }
    
    }
    }
    maketable();
    }
    
    function maketable(edit)
    {
    str="<table width=700 cellspacing=1 cellpadding=2 border=1 align='center'><tr bgcolor='#ececec'bordercolor='#cccccc'><td align='left'><a href='#' onclick=\"sortAsc(0,'s')\" title='Click here to sort by Name'><font face='verdana' size=1 color=blue>Name</font></a></td><td width='10%' align=center><a href='#' onclick=\"sortAsc(10,'s')\" title='Click here to sort by Trip Status'><font face='verdana' size=1 color=blue>Status</font></a></td><td align='center'><a href='#' onclick=\"sortAsc(1,'s')\" title='Click here to sort by Booking No.'><font face='verdana' size=1 color=blue>Booking No.</font></a></td><td align='center'><a href='#' onclick=\"sortAsc(2,'d')\" title='Click here to sort by Departure Date'><font face='verdana' size=1 color=blue>Departure Date</font></a></td><td align='center'><a href='#' onclick=\"sortAsc(3,'s')\" title='Click here to sort by Itinerary'><font face='verdana' size=1 color=blue>Itinerary</font></a></td><td align='center'><a href='#' onclick=\"sortAsc(6,'d')\" title='Click here to sort by Booking Date'><font face='verdana' size=1 color=blue>Booking Date</font></a></td></tr>"
    
    var curdes="<%=curdes%>";
    for(i=0;i<seq.length;i++)
    {
    f=seq[i];
    regsel="";
    norsel="";
    optsel="";
    trasel="";
    buttval="";
    callfunc="";
    stxt="";
    saux="";
    if(arr[f][12]!="")
    {
    saux+=arr[f][12].toUpperCase( );
    }
    if(arr[f][13]!="")
    {
    saux+=".";
    saux+=arr[f][13].toUpperCase( );
    }
    
    if(arr[f][10].toUpperCase( )=="REPEAT")
    {
    regsel="selected";
    stxt="Repeat";
    } 
    else if(arr[f][10].toUpperCase( )=="CANCELLED")
    {
    trasel="selected";
    stxt="<font color=red>Cancelled</font>";
    }
    else if(arr[f][10].toUpperCase( )=="TRASH")
    {
    trasel="selected";
    stxt="Trash";
    }
    else if(arr[f][10].toUpperCase( )=="OPTION")
    
    {
    optsel="selected";
    stxt="Option";
    }
    else 
    {
    norsel="selected";
    stxt="Confirmed";
    }
    
    if(edit==true)
    {
    txvis="hidden";
    txpos="absolute"
    opvis="visible";
    oppos="";
    buttval="Update";
    callfunc="update_regtrip()";
    }
    else
    {
    txvis="visible";
    txpos="";
    opvis="hidden";
    oppos="absolute";
    buttval="Edit";
    callfunc="maketable(true)";
    }
    statustxt="<div style='visibility:" + txvis + ";position:" + txpos + "'><font face='verdana' size='1'>" + stxt +"</font></div>"
    statustxt+="<div style='visibility:" + opvis + ";position:" + oppos + "'><input type='hidden' name='trip" + i + "' value='" + arr[f][1] + "' ><select name='tripstat" + i + "'><option value='Repeat'" + regsel + ">Repeat</option><option value='Confirmed' " + norsel + ">Confirmed</option><option value='Option' " + optsel + ">Option</option><option value='Trash' " + trasel + ">Trash</option></select></div>"
    
    str+="<tr bgcolor='#ececec' bordercolor='#cccccc'>"
    // str+="<td align='center'>" + statustxt + "</td><td align='left'><font face='verdana' size='1'>" + arr[f][0] + "</font></td>"+"<td align='left'><a href='mytrip1.asp?tripid=" + arr[f][11] + "&pnrno="+ arr[f][1] + "&totalfare="+ arr[f][7] + " " + curdes +"'><font face='verdana' size='1' color='blue'>1A/" + arr[f][1] + "</font></a></td>"+"<td align='center'><font face='verdana' size='1'>" + arr[f] + "</font></td>"+" <td align='center'><font face='verdana' size='1'>" + arr[f][3] + "</font></td>"+"<td align='center'><font face='verdana' size='1'>" + arr[f][4] + "</font></td>"+"<td align='right'><font face='verdana' size='1'>" + arr[f][7] + "</font></td>"+"<td align='center'><font face='verdana' size='1'>" + arr[f][9] + "</font></td>"+"<td align='center'><font face='verdana' size='1'>" + saux + "</font></td>"
    str+="<td align='left'><font face='verdana' size='1'>" + arr[f][0] + "</font></td>"+"<td align='center'>" + statustxt + "</td>"+"<td align='center'><font face='verdana' size='1' color='blue'><a href='mytrip_new.asp?pnrno="+ arr[f][1] +"'>" + arr[f][1] + "</a></font></td>"+"<td align='center'><font face='verdana' size='1'>" + arr[f] + "</font></td>"+"<td align='center'><font face='verdana' size='1'>" + arr[f][3] + "</font></td>"+"<td align='center'><font face='verdana' size='1'>" + arr[f][9] + "</font></td>"
    str+="</tr>"
    }
    str+="<tr><td></td></tr></table>"
    document.all.tt.innerHTML=str;
    
    }
    function update_regtrip()
    {
    document.regform.submit();
    return true;
    }
    //-->
    </script>

  • #4
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could've just edited post#1, you know... but what are you asking for, anyway? A confirmation?
    *this message will self destruct in n-seconds*

  • #5
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,093
    Thanks
    15
    Thanked 1 Time in 1 Post
    yeah, can you tell if it is pre-sorted?

  • #6
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes...
    *this message will self destruct in n-seconds*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •