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 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    HELP!: Allow MULTIPLE select on more than 1 column 4 dynamic report

    I am a copy and paster trying to quit ...

    The script below were stolen ... err ... copied from a site and I need to modify it to work with one of my pages where I create a dynamic report by querying a SQL database. Users select the columns they want via check boxes and after submit only allow ONE value from each selected column can be selected via drop-downs.

    The Java script below should help to allow MULTIPLE selections on each column - Could one of the real Java programmers please assist as I am completely ignorant to Java scripting?

    This is the Multi-Select Drop down box code:

    <script language="javascript">
    //Make a multi-select box as you normally would. This script will do the conversion for you.
    //Basically the result looks like a select box with check boxes - It's an improvement over the standard
    //multi-select box in that you don't need to know the magic key combination for selecting a second item
    //without losing the first!
    //NOTE: Your multi-select box NAME must end with []
    //<select id="something" name="something[]" multiple size=5>
    //This file saved as js_MultipleSelect.asp in the scripts directory

    function addEvent(el,ev,fn){

    if(el.attachEvent)el.attachEvent('on'+ev,fn);
    else if(el.addEventListener)el.addEventListener(ev,fn,false);
    }

    addEvent(window,'load',buildMultiselects);

    function buildMultiselects(){

    do{
    found=0;
    a=document.getElementsByTagName('select');

    for(b=0;b<a.length,!found;b++){

    var ms=a[b];

    if(ms==null)break;

    if(ms.name.substring(ms.name.length-2,ms.name.length)=='[]'){
    found=1;
    disabled=(ms.disabled)?1:0;
    width=ms.offsetWidth;
    height=ms.offsetHeight;
    el=document.createElement('div');
    el.style.overflow='auto';
    el.style.width=width+"px";
    el.style.height=height+"px";
    el.style.border="2px solid #000";
    el.style.borderColor="#333 #ccc #ccc #333";
    c=ms.getElementsByTagName('option');

    for(d=0;d<c.length;d++){
    el2=document.createElement('span');
    el2.style.display="block";
    el2.style.border="1px solid #eee";
    el2.style.borderWidth="1px 0";
    el2.style.font="10px arial";
    el2.style.lineHeight="10px";
    el2.style.paddingLeft="20px";
    el3=document.createElement('input');
    el3.type="checkbox";

    if(c[d].selected){
    el3.checked="checked";
    el3.defaultChecked=true;
    }

    if(disabled)el3.disabled="disabled";
    el3.value=c[d].value;
    el3.style.marginLeft="-16px";
    el3.style.marginTop="-2px";
    el3.name=ms.name;
    el4=document.createTextNode(c[d].innerHTML);
    el2.appendChild(el3);
    el2.appendChild(el4);
    el.appendChild(el2);
    }
    ms.parentNode.insertBefore(el,ms);
    ms.parentNode.removeChild(ms);
    }
    }
    }while(found);
    }
    </script>


    This is the HTML used for testing the script above - it works like a charm - only if I could convert it to help me in my application:


    <!--#include file="scripts/js_MultipleSelect.asp"-->
    <%
    dim DATABASE2LOOK4
    'dim rs
    DATABASE2LOOK4 = Request.Form("DATABASE2LOOK4")
    'set rs = dbConn.Execute("SELECT [dbid], [name] FROM [sysdatabases] ORDER BY [dbid] ASC")
    %>
    <!--BEGIN CODE HERE-->
    <FORM ACTION="multiple_select_next_page.asp" METHOD="post" ID=next_page_QRY NAME=next_page_QRY>
    <script language="VBScript">
    Private Sub btnact_OnMouseOver()
    btnact.style.color = "#000000"
    btnact.style.backgroundColor = "#ff0000"
    End Sub
    Private Sub btnact_OnMouseOut()
    btnact.style.color = "#ffffff"
    btnact.style.backgroundColor = "#990000"
    End Sub
    Public Sub btnact_OnClick()
    divInit.style.display = ""
    document.getElementById("next_page_QRY").submit
    End Sub
    </script>

    <TABLE WIDTH="100%" HEIGHT=10px BORDER="0" CELLSPACING="0" CELLPADDING="0">
    <tr width=100% height=100% align=center>
    <td width=10% align=center></td>
    <td width=450px align=left>
    <select id="something" name="something[]" multiple size=5>
    <option value="One Thousand One Hundred" >One Thousand One Hundred
    <option value="Two Thousand Two Hundred" >Two Thousand Two Hundred
    <option value="Three Thousand Three Hundred" >Three Thousand Three Hundred
    <option value="Four" >Four
    <option value="Five" >Five
    <option value="Six" >Six
    <option value="Seven" >Seven
    <option value="Eight" >Eight
    <option value="Nine" >Nine
    <option value="Ten" >Ten
    </select>
    </td>
    <td width=10% align=center></td>
    </tr>
    </TABLE>
    <TABLE WIDTH="100%" HEIGHT=360px BORDER="0" CELLSPACING="0" CELLPADDING="0" ALIGN=center>
    <tr width=100% height=100% align=center>
    <td width=10% align=center></td>
    <td width=80% align=center>
    <INPUT CLASS=INPUT1 TYPE=button VALUE=Submit ID=btnact NAME=btnact STYLE="WIDTH:25%">
    </td>
    <td width=10% align=center></td>
    </tr>
    </TABLE>
    </FORM>

    This is the 1st page of my appl - save as Select_Columns.asp or whatever:
    Obviously you should have a database that use a view on multiple tables and many columns ... The user selects the columns he wants for his report on this page via check boxes.

    <!--BEGIN CODE HERE-->
    <%
    dim ColumnName
    dim ColumnID
    ColumnID=Request.Form("ColumnID")
    ColumnName=Request.Form("ColumnName")
    set dbRS=Server.CreateObject("ADODB.Recordset")
    set dbRS=dbConn.Execute("SELECT * FROM view_DB_USERTRACKING")
    %>
    <FORM ACTION="Report_01.asp" METHOD="post" id=USERTRACKING_Report name=USERTRACKING_Report>
    <P><STRONG>Tick COLUMNS to display in report and SUBMIT at bottom of page:</STRONG></P>
    <TABLE WIDTH='100%' HEIGHT=20px ALIGN='center' BORDER='1' CELLSPACING='0' CELLPADDING='0'>
    <TR WIDTH='100%' ALIGN=center>
    <TD WIDTH='30%' ALIGN=center></TD>
    <TD WIDTH='20%' ALIGN=center><STRONG>ColumnName</STRONG></TD>
    <TD WIDTH='10%' ALIGN=center><STRONG>ColumnID</STRONG></TD>
    <TD WIDTH='30%' ALIGN=center></TD>
    </TR>
    <%ColumnID=1%>
    <%for each ColumnName in dbRS.Fields%>
    <%Response.Write "<TR WIDTH=100% ALIGN=center>"%>
    <%Response.Write "<TD WIDTH='30%'></TD>"%>
    <%Response.Write "<TD WIDTH='20%' ALIGN=left>"%>
    <%Response.Write "<INPUT TYPE='checkbox' NAME='ColumnName'"%>
    <%Response.Write " VALUE="%>
    <%=(ColumnName.name)%>
    <%if "'(ColumnName)'"="'(ColumnName.name)'" then%>
    <%Response.Write " CHECKED>"%>
    <%=(ColumnName.name)%>
    <%Response.Write "</TD>"%>
    <%else%>
    <%Response.Write ">"%>
    <%=(ColumnName.name)%>
    <%Response.Write "</TD>"%>
    <%end if%>
    <%Response.Write "<TD WIDTH='10%' ALIGN=center>"%>
    <%=(ColumnID)%>
    <%Response.Write "</TD>"%>
    <%Response.Write "<TD WIDTH='30%' ALIGN=center></TD>"%>
    <%Response.Write "</TR>"%>
    <%ColumnID=ColumnID+1%>
    <%next%>
    </TABLE>
    <TABLE WIDTH='100%' HEIGHT=20px ALIGN=center>
    <TR WIDTH='100%' HEIGHT=100% ALIGN=center>
    <TD></TD>
    <TD WIDTH='25%' ALIGN=center>
    <INPUT TYPE=submit VALUE=Submit ID=btnact NAME=btnact STYLE='WIDTH:100%'>
    </TD>
    <TD></TD>
    </TR>
    </TABLE>
    </FORM>
    <!--END CODE HERE-->

    Lot of my code is hidden in the include files (PageHeader, PageFooter, DB_NAME, DB_Close) where a lot of declarations are done, connection string to SQL etc.

    This is the 2nd page of my appl - Save as Report_01.asp:
    Each checked column are shown with a drop-down for the values in the column.

    Here the user can select only 1 value or ALL from each column - I want more than 1 or only one or all - The Java script on top is the answer, I don't know zilch about Java - Please help!

    <!--BEGIN CODE HERE-->
    <%
    dim ColumnName
    dim ColumnValue
    dim ColumnID
    dim rs2
    ColumnName=Request.Form("ColumnName")
    ColumnValue=Request.Form("ColumnValue")
    ColumnID=Request.Form("ColumnID")
    set dbRS=Server.CreateObject("ADODB.Recordset")
    set dbRS=dbConn.Execute("SELECT " & Request.Form("ColumnName") & " FROM view_DB_USERTRACKING")
    %>
    <FORM ACTION="DB_USERTRACKING_Report_02.asp" METHOD="post" id=USERTRACKING_Report name=USERTRACKING_Report>
    <P><STRONG>VALUES that display SELECT means ALL VALUES!</STRONG></P>
    <P><STRONG>Select VALUES to display in report and SUBMIT at bottom of page:</STRONG></P>

    <TABLE WIDTH='100%' HEIGHT='20px' ALIGN='center' BORDER='1' CELLSPACING='0' CELLPADDING='0'>
    <TR WIDTH='100%' ALIGN='center'>
    <TD WIDTH='10%' ALIGN='center'></TD>
    <TD WIDTH='5%' ALIGN='center'><STRONG>ColumnID</STRONG></TD>
    <TD WIDTH='25%' ALIGN='center'><STRONG>ColumnName</STRONG></TD>
    <TD WIDTH='25%' ALIGN='center'><STRONG>ColumnValue</STRONG></TD>
    <TD WIDTH='10%' ALIGN='center'></TD>
    </TR>
    <%ColumnID=1%>
    <%for each ColumnName in dbRS.Fields%>
    <%Response.Write "<TR WIDTH=100% ALIGN=center>"%>
    <%Response.Write "<TD WIDTH='10%'></TD>"%>
    <%Response.Write "<TD WIDTH='5%' ALIGN=left>"%>
    <%Response.Write "<INPUT TYPE='text' NAME='ColumnID'"%>
    <%Response.Write " VALUE="%>
    <%Response.Write "'"%>
    <%=(ColumnID)%>
    <%Response.Write "'"%>
    <%Response.Write ">"%>
    <%Response.Write "</TD>"%>
    <%Response.Write "<TD WIDTH='25%' ALIGN=left>"%>
    <%Response.Write "<INPUT TYPE='text' NAME='ColumnName'"%>
    <%Response.Write " VALUE="%>
    <%Response.Write "'"%>
    <%=(ColumnName.name)%>
    <%Response.Write "'"%>
    <%Response.Write ">"%>
    <%Response.Write "</TD>"%>
    <%Response.Write "<TD WIDTH='25%' ALIGN=left>"%>
    <%set rs2=Server.CreateObject("ADODB.Recordset")%>
    <%set rs2=dbConn.Execute(" SELECT DISTINCT " & ColumnName.name & " FROM view_DB_USERTRACKING ORDER BY " & ColumnName.name & " ASC")%>
    <%Response.Write "<SELECT ID="%>
    <%Response.Write "'ColumnValue'"%>
    <%Response.Write " NAME="%>
    <%Response.Write "'ColumnValue'"%>
    <%Response.Write ">"%>
    <%Response.Write "<OPTION VALUE="%>
    <%Response.Write "'"%>
    <%Response.Write "ALL"%>
    <%Response.Write "'"%>
    <%Response.Write ">"%>
    <%Response.Write ">SELECT ALL<"%>
    <%Response.Write "</OPTION>"%>
    <%rs2.MoveFirst%>
    <%do while not rs2.EOF%>
    <%if (rs2.fields(ColumnName.name))=(ColumnName.value) then%>
    <%Response.Write "<OPTION VALUE="%>
    <%Response.Write "'"%>
    <%=rs2.fields(ColumnName.name)%>
    <%Response.Write "'"%>
    <%Response.Write " SELECTED>"%>
    <%=rs2.fields(ColumnName.name)%>
    <%Response.Write "</OPTION>"%>
    <%else%>
    <%Response.Write "<OPTION VALUE="%>
    <%Response.Write "'"%>
    <%=rs2.fields(ColumnName.name)%>
    <%Response.Write "'"%>
    <%Response.Write ">"%>
    <%=rs2.fields(ColumnName.name)%>
    <%Response.Write "</OPTION>"%>
    <%end if%>
    <%rs2.MoveNext%>
    <%loop%>
    <%Response.Write "</SELECT>"%>
    <%Response.Write "</TD>"%>
    <%Response.Write "<TD WIDTH='10%' ALIGN=center>"%>
    <%Response.Write "</TD>"%>
    <%Response.Write "</TR>"%>
    <%ColumnID=ColumnID+1%>
    <%next%>
    </TABLE>
    <TABLE WIDTH='100%' HEIGHT=20px ALIGN=center>
    <TR WIDTH='100%' HEIGHT=100% ALIGN=center>
    <TD></TD>
    <TD WIDTH='25%' ALIGN=center>
    <INPUT TYPE=submit VALUE=Submit ID=selValues NAME=selValues STYLE='WIDTH:100%'>
    </TD>
    <TD></TD>
    </TR>
    </TABLE>
    </FORM>
    <%set rs2=nothing%>
    <!--END CODE HERE-->
    Last edited by S1m0ne; 01-12-2005 at 07:05 AM.


 

Posting Permissions

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