Search these areas:
Help
Support Forums
Product Info



-Introduction
-DataWeb: What's New
-Creating an Application
-The DataWeb Designer
-Application Management
-Data Tables
-Data Tables
-Views
-Templates
-Components
-Data Analysis
-Members
-Security
-Importing
-Exporting
-FTP
-JavaScript
-Object Model
-Full-Text Search
-Domain and Email Hosting
-HotBlock Modules
-Account Management
-Glossary
-New Responsive UI Module





DataWeb Help
Support Forums
Tutorial
Script Library
Knowledge Base

Home > Support

Support Forum



Many checkboxes, one name but inaccessable
jax asked:
Javascript allows you to create multiple checkboxes with the same name:

<input type="checkbox" name="list" value="bob" />
<input type="checkbox" name="list" value="sally" />

When this is posted, you get an array named "list" with all values that have been checked (eg, list[0].value would equal "bob", if "bob" was checked).  Extremely handy.

I have such a element in a dataregion that I hand crafted.  When I post in my .data I can request the parameter "list", and sure enough is has a length of the correct number of checked items.  The type, however, is an object, not an array.  There is no .value field.  I know there's data there, but I can't seem to get to it.

Help me Mr. Wizard!
 
  dougl responded:
  Wait until the next product update. Check your inbox for more details.  
  jax responded:
  Doh!  
  brendanx responded:
  There will be 2 new methods on the Request object:

getParameterNames();
getParameterValues(name_str);

which should allow you access to all of the request parameters, regardless of whether you know the exact construction of the posting form.

In your case, I believe all you will need is getParameterValues which will return you an array of values for the name 'list'.

Your post really resolves to post data that looks like:

list=bob&list=sally

The problem with our current implementation is that it only supports getParameter() which returns you only one of the values.  It does not work for multi-select values.

If you can't wait (which I suggest, since it should happen this week), you do the parsing yourself in script with the function below.

function getParameterValues(name_string)
    {
    var arr;
    var arrParams = request.getData().split("&");
    var arrVal = new Array();
    for (var i = 0; i < arrParams.length; i++)
        {
        arr = arrParams[i].split("=");
        if (String.equalIgnoreCase(arr[0], name_string))
            arrVal.push(arr[1]);
        }
    return arrVal;
    }
 
  dougl responded:
  DataWeb considers this issue closed.
If you have additional questions or comments about this issue, please open it again.
If you have questions about a different topic please open a new support question.

Thanks,
DataWeb Support
 
  jax responded:
  This issue is open.  
  jax responded:
  I noticed the product got revved last night so I anxiously tried Brendan's solution. 

My HTML looks like the following:

<input type="checkbox" name="list" value="bob" />
<input type="checkbox" name="list" value="sally" />

My script looks like:

userArray = request.getParameterValues("list");
for (var i=0; i<userArray.length; i++){
    script.log("userArray["+i+"]", userArray[i] +" "+ userArray[i],value);
}

The output is:

Userarray[0]     on on
Userarray[1]     on on

I know, this will probably be in the updated help docs but how do I get the *value* out of "list"?
 
  brendanx responded:
  Strange looking call to Script.log, Jax, (Script.log only takes 2 parameters, and I don't understand why you output the value twice with a space separator) but I can't immediately see what you are doing wrong.

I have, however, verified against my own similar checkboxes that everything works as I would expect on the production servers.

How about you add the following script.log call to your debugging code:

Script.log("getData", request.getData());

That way you can see if the raw data matches up with your expectations.  This will help narrow the bug to either your form, or your script.
 
  jax responded:
  Wee!  Thanks for the advise.  It does indeed work.

-jax

PS  It was supposed to read:

script.log("userArray["+i+"]", userArray[i] +" "+ userArray[i].value);

Sorry for the confusion.
 
  dougl responded:
  DataWeb considers this issue closed.
If you have additional questions or comments about this issue, please open it again.
If you have questions about a different topic please open a new support question.

Thanks,
DataWeb Support
 
  Please Log On
or create your own DataWeb Account.
Affiliate | Partner | Terms of Use | Privacy Policy | Contact Us | Pricing | Bring DataWeb In-House    
DataWeb, 720 North 10th Street, A #145, Renton, Washington 98057 *425-583-5970* Fax 484-770-4706* Email Us