post all values in select box /listbox - html

I have a selectbox on a form - which I've turned in to a list box by putting
<select id="Select1" name="D1" size="5" style="width: 220px">
I'm filling this select/listbox with values...
When I post the form how can I get all the values in the select box..is this possible or am I only able to get one that has been selected.
Trouble is I want all the values in the select (I'm not selecting any as such)
Any ideas?

Before submitting the form you can use some JavaScript to pull the items out of the select and put them into a hidden text field (as a delimited string)
For example, you can get the values using
var select1 = document.getElementById('select1');
var values = new Array();
for(var i=0; i < select1.options.length; i++){
values.push(select1.options[i].value);
}
var allValues = values.join(";");
alert(allValues);
Hope that helps.

How are you adding the values to the list box? Are they static or are they pulled from a database.
If you're pulling from the database I would create a function that you use to get the data and bind to the list box.
Then use that same function when you want to get those values after the post. You may have to use some hidden fields to pass along any parameters you use to get the values for the list box in the first place.
example:
function get_models_for_make(int make_id)
mydata_rs = SELECT name, id FROM models WHERE make_id = make_id
return mydata_rs
end
so you could use this data to bind the objects to your listbox and also use it to get the values later that you did bind to your list box.

for (int i = source.Items.Count - 1; i >= 0; i--)
{
ListItem item = source.Items[i];
if (moveAllItems)
item.Selected = true;
if (item.Selected)
{
// if the target already contains items, loop through
// them to place this new item in correct sorted order
if (target.Items.Count > 0)
{
for (int j = 0; j < target.Items.Count; j++)
{
if (target.Items[j].Text.CompareTo(item.Text) > 0)
{
target.Items.Insert(j, item);
item.Selected = false;
break;
}
}
}
// if item is still selected, it must be appended
if (item.Selected)
{
target.Items.Add(item);
item.Selected = false;
}
// remove the item from the source list
source.Items.Remove(item);
}
}

Related

Passing variable to htp.p in a PL/SQL Dynamic Content

I am trying to pass a value in a variable for validation based on a db column and a checkbox on the UI component.
NOTE: Max_Set is the variable holding the maximum number from the DB column which is to be validated against the numberOfChecked items. However, when i pass Max_Set to the htp.p script, i am unable to use the value in the variable.
select num into Max_Set from table where column_name = name;
htp.p('<script type="text/javascript">');
htp.p('function ValidateSelection1()
{
var checkboxes = document.getElementsByName("student");
var numberOfCheckedItems = 0;
var Max_num = Max_Set
for(var i = 0; i < checkboxes.length; i++)
{
if(checkboxes[i].checked)
numberOfCheckedItems++;
}
if(numberOfCheckedItems > Max_num)
{
alert("You cant select more than the required number for this SL Site!");
return false;
}
}');
htp.p('</script>');
How can I use the value from Max_Set into htp.p script without it being considered as a string?
In your pl/sql code, everything within the htp call is treated as a string. If you want to use variables that are declared in pl/sql, you can concatenate (||) to put it all together. I replaced the "Max_Set" with "l_max_set" to indicate that this is a local pl/sql variable and not a javascript variable and the initcap tends to make it look like javascript.
select num into l_max_set from table where column_name = name;
htp.p('<script type="text/javascript">');
htp.p('function ValidateSelection1()
{
var checkboxes = document.getElementsByName("student");
var numberOfCheckedItems = 0;
var Max_num = '||l_max_set||';
for(var i = 0; i < checkboxes.length; i++)
{
if(checkboxes[i].checked)
numberOfCheckedItems++;
}
if(numberOfCheckedItems > Max_num)
{
alert("You cant select more than the required number for this SL Site!");
return false;
}
}');
htp.p('</script>');

Is using a variable on HTMLElement.style.variable in Angular/TypeScript possible?

I try to implement an updateStyle(...)-method inside of an Angular-Component.
With this method specific elements with unique id's shall be styled.
Following code-snippet leads to:
Property 'variable' does not exist on type 'CSSStyleDeclaration'.
Is it possible to make angular compile anyway, so the variable is filled with a legit value in runtime or do I have to implement the method for every style-declaration, that I am going to use the method on?
updateStyle(id, variable, value){
var components = document.querySelectorAll("[id]") as NodeListOf<HTMLElement>;
for(var i = 0; i < components.length; i++) {
if(components[i].getAttribute("id") == id) {
components[i].style.variable = value;
}}}
You can put variable in square brackets like this:
updateStyle(id, variable, value) {
var components = document.querySelectorAll("[id]") as NodeListOf<HTMLElement>;
for (var i = 0; i < components.length; i++) {
if (components[i].getAttribute("id") == id) {
***components[i].style[variable] = value;***
}
}
}

AS3 datagrid - Hide a row

I'm using 2 comboboxes to filter a dataGrid that has been populated via csv file. The first combobox filters the columns and works fine:
//Listener and function for when the Agreement ID is selected
agreement_cb.addEventListener(Event.CHANGE, agreement);
function agreement(event:Event):void
{
//get the number of columns
var columnCount:Number = myGrid.getColumnCount();
for (var i:int=0; i<columnCount; i++)
{
myGrid.getColumnAt(i).visible = false;
}
var columnNumber:Number = agreement_cb.selectedItem.data;
myGrid.getColumnAt(columnNumber).visible = true;
myGrid.getColumnAt(0).visible = true;
myGrid.columns[0].width = 200;
}
But I can't find anything on how to get the same type of function to hide all of the rows except the one they select from the second drop-down (codes_cb).
Any help is appreciated...
UPDATE:
loadedData = myLoader.data.split(/\r\n|\n|\r/);
loadedData.pop();
for (var i:int=0; i<loadedData.length; i++)
{
var rowArray:Array = loadedData[i].split(",");
loadedData[i] = {"SelectAgreement":rowArray[0],"KSLTPROF0057":rowArray[1] .........};
}
loadedData.shift();
myGrid.columns = ["SelectAgreement", "KSLTPROF0057", ......];
import fl.data.DataProvider;
import fl.controls.dataGridClasses.DataGridColumn;
myGrid.dataProvider = new DataProvider(loadedData);
A DataGrid always shows all objects in its dataProvider, so to hide rows, you need to hide the data objects. Some classes that work as dataProviders have this functionality built in that makes this really easy (Any Class that implements IList can be operate as a dataProvider), however fl.data.DataProvider is not one of those classes.
So I will provide answers using both, if you can, I highly recommend using mx.collections.ArrayCollection over fl.data.DataProvider.
Section 1: fl.data.DataProvider
For this I'm assuming that your loadedData array is a class property, not declared in a function.
function agreement(event:Event):void
{
//your existing code here
var dataProvider:DataProvider = MyGrid.dataProvider as DataProvider;//recover the dataprovider
dataProvider.removeAll();//remove all rows
for (var x:int = 0; x<loadedData.length; x++)
{
if (loadedData[x] == "SELECTION MATCH") //insert here your selection criteria
{
dataProvider.addItem(loadedData[x]); //add it back into the dataProvider
}
}
}
function resetFilter():void
{
var dataProvider:DataProvider = MyGrid.dataProvider as DataProvider;//recover the dataprovider
dataProvider.removeAll(); //prevent duplication
dataProvider.addItems(loadedData);//reload all rows
}
Section 2: mx.collections.ArrayCollection
My reasoning for recommending this is because ArrayCollection already has the functions to do this without the risk of data being lost by objects losing scope, it also reduces the amount of code/operations you need to do. To do this we use ArrayCollection.filterFunction & ArrayCollection.refresh() to filter the "visible array" without changing the source.
private var dataProvider:ArrayCollection = new ArrayCollection(loadedData);
MyGrid.dataProvider = dataProvider;
function agreement(event:Event):void
{
//your existing code here
dataProvider.filterFunction = myFilterFunction;//use my filter
dataProvider.refresh();//refresh the visible list using new filter/sort
}
function resetFilter():void
{
dataProvider.filterFunction = null;//clear filter
dataProvider.refresh();//refresh the visible list using new filter/sort
}
function myFilterFunction(item:Object):Boolean
{
if (item == "SELECTION MATCH") return true;//insert your selection criteria here
else return false;
}
the filterFunction accepts a function and uses it to test each object in the ArrayCollection, the function has to return a Boolean, true for "Yes, display this object" and false for "Do not diplay".

adding a new row only when the last row in modified

Problem description:
I have a table with three rows. The first row contains a drop down. When a user selects a drop down option, a new row should be generated beneath the current last row. How can I tweak this code to such that a new row is generated only when the user selects a drop down option of the current last row, and not any other row?
JSFiddle: http://jsfiddle.net/JPVUk/13/
var ViewModel = function() {
var self = this;
self.items = ko.observableArray([{comment:'first comment', amount:0}]);
self.addNewItem = function(){
self.items.push(new Item('',0));
};
}
var Item = function(comment, amount) {
var self = this;
self.comment = ko.observable(comment);
self.amount = ko.observable(amount);
};
vm = new ViewModel()
ko.applyBindings(vm);
What I am struggling to do:
So, since I want to bind the change event to the last row, here's how I am approaching it:
<select class="input-small" data-bind="items()[items.length-1] ? event: { change: $root.addNewItem }">
This is however not working. Any ideas folks ?
Can't you just past the row that causes the event to fire to your handler and check it there?
Something like this:
<select class="input-small" data-bind="event: { change: $root.addNewItem }">
And then:
self.addNewItem = function(row){
if (row == self.items()[self.items().length - 1]) {
self.items.push(new Item('',0));
}
};
http://jsfiddle.net/JPVUk/14/
I'm not sure if jQuery was acceptable so this just uses DOM. Basically use the event object passed to knockout. Traverse a little dom and determine is the event target is a child of the last row in the parent table:
var tableRow = event.target.parentNode.parentNode,
body = tableRow.parentNode,
nodes = body.childNodes,
children = [];
for (var i = 0; i < nodes.length; i++) {
// remove non-element node types. ie textNodes, etc.
if (nodes[i].nodeType === 1) {
children.push(nodes[i]);
}
}
if (tableRow === children[children.length - 1]) {
self.items.push(new Item('', 0));
}

how to compare two array collection using action script

how to compare two arraycollection
collectionArray1 = ({first: 'Dave', last: 'Matthews'},...........n values
collectionArray = ({first: 'Dave', last: 'Matthews'},...........n values
how to compare..if equal just alert nochange if not alert chaged
If you just want to know if they are different from each other, meaning by length, order or individual items, you can do the following, which first checks to see if the lengths are different, then checks to see if the individual elements are different. This isn't terribly reusable, it's left as an exercise for the reader to split this apart into cleaner chunks :)
public function foo(coll1:ArrayCollection, coll2:ArrayCollection):void {
if (coll1.length == coll2.length) {
for (var i:int = 0; i < coll1.length; i++) {
if (coll1[i].first != coll2[i].first || coll1[i].last != coll2[i].last) {
Alert.show("Different");
return;
}
}
}
Alert.show("Same");
}
/* elements need to implement valueOf
public function valueOf():Object{}
*/
public static function equalsByValueOf(
first:ArrayCollection,
seconde:ArrayCollection):Boolean{
if((first==null) != (seconde==null) ){
return false;
}else if(!first && !seconde){
return false;
}
if(first.length!=seconde.length){
return false;
}
var commonLength:int = first.length;
var dictionary:Dictionary = new Dictionary();
for(var i:int=0;i<commonLength;i++){
var item1:Object = first.getItemAt(i);
var item2:Object = seconde.getItemAt(i);
dictionary[item1.valueOf()]=i;
dictionary[item2.valueOf()]=i;
}
var count:int = 0;
for (var key:Object in dictionary)
{
count++;
}
return count==commonLength;
}
/* valueOf sample
* something like javaObject.hashCode()
* use non changing fields(recommended)
*/
public function valueOf():Object{
return "_"+nonChangeField1+"_"+nonChangeField2+"...";
}
I was going to say this.
if(collectionArray === collectionArray1)
But that wont work (not triple = signs). As === is used to see classes.
I would write a function called check if object exists in array.
Create an array to hold elements that are not found. eg notFound
in Collection1 go through all the element and see if they exist in Collection2, if an element does not exist, add it to the notFound array. Use the function your created in step1
Now check Collection2, if an element is not found add it to the notFound array.
There is no 5.
Dude, use the mx.utils.ObjectUtil... the creators of actionscript have already thought about this.
ObjectUtil.compare(collection1, collection2) == 0;