Manage Learn to apply best practices and optimize your operations.

Adding And Deleting Entries Between Lists On Web Using Java Script

The code below are called by button Add and Replace. The buttons call functions
1 and 3 respectively.Write the function calls in the Onclick events of the
buttons.
Code Written By:Sudha Ganesan
Date:22nd September1999
Version:1.0
Description:Java Script functions to add or delete items from a list as called
by the respective
button click events
There are 4 major functions in the JS Header.
The functions are numbered 1 to 4 in the description

**************function1:changeValues(form)----Called By Add
button*******************
Strores the value of an item selected in List L1 in a
variable L1
This value is passed as a parameter to a function
call:-getValueOptions(L1)
The return value of the called function is an
array---myArray
forall values in the array a loop sets the corresponding
values in the L2 list as the array values
at those indices.

**************function2:getValueOptions(L1)*******************
The slected item in L1 is used as a parameter by this
function.
a1 stands as a temporary field in the form which tracks
all updates to L2.
The value of this field is stored in a variable 's'
The indexOf method checks for occurance of the L1 value
in s.
If the value exists
alerts for duplicate values.
Else
appends the selected L1 value to a1 field
delimitered with semicolons.

End if
s is then taken as the value in the whole a1 field
converted into string format.
The split method of Javascript splits the s value with
delimiters as ";"
The myArray gets new size and values as per the
selection.


**************function3:replaceValues(form)*******************---Called By
Replace button
Strores the value of an item selected in List L2 in a
variable L2
This value is passed as a parameter to a function
call:-replacingValue(L2)
The return value of the called function is an
array---myArray
forall values in the array a loop sets the corresponding
values in the L2 list as the array values
at those indices.

**************function4:replaceValues(form)*******************
The slected item in L2 is used as a parameter by this
function.
a1 stands as a temporary field in the form which tracks
all updates to L2.
The value of this field is stored in a variable 's'
The following are the variables which play a major role
in the replacement:-

***Position1***
The position of L2 in the a1 field is retrieved using the
indexOf Javascript method.

***StringLength***
StringLength is a variable which gives the length of the
L2 value(It is always 1---Only one sel;ection allowed)

***TempString***
TempString retrieves all the items above the selected
value in L2.
This is done using the substring method which retrieves
the string from a starting postion to an end position.
In this case from start to the selected item position.

***TempString2***
The Positon1+StringLength is stored in a variable x.
TempString2 retrieves the later part of the list from
the position of
function changeValues ( form ) {
var L1 = document.forms[0].L1.options[document.forms[0].L1.selectedIndex].text;
var myArray = getValueOptions (L1 ) ;
form.L2.options.length = myArray.length;
for ( var i = 0; i < myArray.length; i++){
form.L2.options[i].value=myArray[i];
form.L2.options[i].text = myArray[i];
}
}
function getValueOptions (L1) {
if (L1==""){
alert("Empty Values!!!!!!!!!");
}
var s = document.forms[0].a1.value;
var x = document.forms[0].L1.options[document.forms[0].L1.selectedIndex].text;
if(s.indexOf(x)==-1){
document.forms[0].a1.value=s+x+";";
var s = document.forms[0].a1.value;
}
else{
alert("Duplicate Values!!!!!!!!!!!");
}
s = s.substring( 0, s.length);
var myArray = s.split(";");
return myArray;
}
//--------------------------------
function replacingValue (L2 ) {
var s = document.forms[0].a1.value;
Position1=s.indexOf(L2);
StringLength=L2.length;
TempString1=s.substring(0,Position1);
var x=Position1+StringLength
TempString2=s.substring(x+1,s.length);
ResultString=TempString1+TempString2;
result = ResultString.substring( 0, ResultString.length);
document.forms[0].a1.value= result;
finala=document.forms[0].a1.value
var myArray = finala.split(";");
return myArray;

}
function replaceValues ( form ) {
var L2 = document.forms[0].L2.options[document.forms[0].L2.selectedIndex].text;
var myArray =replacingValue (L2 ) ;
form.L2.options.length = myArray.length;
for ( var i = 0; i < myArray.length; i++){
form.L2.options[i].value=myArray[i];
form.L2.options[i].text = myArray[i];
}
}

Dig Deeper on Domino Resources - Part 2

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close