Jump to content
  • 0

Passing Parameters from Multi-Select Listbox


DAG4Debt

Question

I have configured a search form that allows for multi-select listboxes. I'd like to pass them and run a query from a table. The parameters pass fine, but they look like this (two cities selected from the multi-select): "Chula Vista||cb||El Cajon". When I try to use this Virtual parameter as a data field using pre-defined criteria for a tabular report, no records are displayed. The report should generate all matching records for the two cities, Chula Vista AND El Cajon.

How can I pass parameters using the multi-select variable (let's call it Virtual1) and run those parameters successfully against the data fields? By the way, I tried changing the comparison type to "contains", but no go. Please help.

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

InsertRecord prefix is used for submission form field ids so it's not relevant to search form. In search form the search fields start with Value1_1, second field will be value2_1, and so on. Now if you have deleted and added fields, this order might be different so it is always recommended to use a developer tool such as Firebug to inspect the element and find the proper id, your code should be like:

var fieldName = "Value1_1";

var x1=document.getElementsByName(fieldName);

x1[0].multiple=true;

function splitAndParse()

{

var result = "";

var cleanResult = "";

for (var i = 0; i < x1[0].length; i++) {

if (x1[0].options.selected) {

result += "\""+x1[0].options.value+"\"" + " OR " ;

}

}

document.getElementById("cbParamVirtual1").value = result;

}

document.getElementById("caspioform").onsubmit=splitAndParse;

Link to comment
Share on other sites

  • 0

I was trying that, but can't get it to work. Are you saying that the values do not include "||cb||" but a comma instead? I was trying to use the replace function (i.e. [@Field].replace=? but that wasn't working. DO you have some sample code to change the values in the table to include the OR statement instead of "," or "||cb||"?

Here is my code:

v_Virtual_City=[@Virtual_City].replace(/,/g," OR ");

document.write(v_Virtual_City);

The document.write line is just to test, but the "," is not replaced. I also tried "||cb||" but that's not replaced either.

Link to comment
Share on other sites

  • 0

multi-select listbox in a search/report DataPage provides the functionality that you need. However as I understand you have separated your search than results so you have two DataPages passing and receiving search criteria as parameters. In this case you need to custom implement the multi-select functionality as it is not a standard feature in such situation. There is a forum post which provides the implementation method and a sample JavaScript, http://forums.caspio.com/index.php/topic/3694-enable-multiple-selection-for-listbox-with-virtual-fields/?hl=%2Benable+%2Bmultiple+%2Bselection. Does that help? Cheers, Barbara

Link to comment
Share on other sites

  • 0

Yes and no. I am using a search and report page for an initial result table. I am passing the search parameters to a new table and then returning them to another results table so the user doesn't have to repeat entering search criteria. The parameters are generated from a search and report datapage. I have used the code provided and modified it, but I can't get it to work. I am using InsertRecord instead of cbParamVirtualX for the field name because it is generated from a search/report datapage. I also have a hidden virtual field for cbParamVirtual1 which is where the new "OR" results are supposed to go. That variable, however, passes as blank. I am wracking my brain here. The Location_City field is the one that needs to be parsed with names separated with "OR". It is from a cascading listbox. Here is my code:

var fieldName = "InsertRecordLocation_City";

var x1=document.getElementsByName(fieldName);

x1[0].multiple=true;

function splitAndParse()

{

var result = "";

var cleanResult = "";

for (var i = 0; i < x1[0].length; i++) {

if (x1[0].options.selected) {

result += "\""+x1[0].options.value+"\"" + " OR " ;

}

}

if (x1[0].length > 4) { cleanResult = result.substring(0,(result.length-4)); }

document.getElementById("cbParamVirtual1").value = cleanResult;

}

document.getElementById("caspioform").onsubmit=splitAndParse;

Link to comment
Share on other sites

  • 0

Three total. The first is the search and report page. It is on that page the user selects initial filtering criteria and the report is generated. The parameters are passed to page 2.

Page 2 is details page for links checked from page 1. The parameters from page 2 to page 3. All parameters for the filtering criteria pass fine except the parameters that I need to parse for the multi-celect: Location_City.

Page 3 is a report/table datapage with criteria selected for the report from the parameters transferred from page 1. Like I said everything works fine except that "OR" field for the multi-select which appears to be passing either blank or empty.

Link to comment
Share on other sites

  • 0

Do I understand correctly, that your multi-select is the standard multi-select listbox on a search page? If yes, than you were right, that passed values will be separated by ||cb||. In this case, to parse the value you can use the following JS:

var str="[@Virtual_City]";

while (str.indexOf("||cb||")!=-1) {

str=str.replace("||cb||", " OR ");

}

I'm not sure how do you want to pass it to the next page. Will you be redirected to it after page submission or you want to have a link?

Any way your third page should be predefined criteria. And you need to set Contains comparison type for the City field and receive passed parameter.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...