473,383 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Dont allow duplicate values in a dynamic div

10
I am selecting multiple items from a selectbox and on click of a button adding them dynamically to a <div>.
I am adding it as children to the div ...something like checkbox + <selecteditem>.

Next time when the user selects an option which he already added in the div, he should not be allowed to do so.
how can i achieve this? a string match or how ? please send the code

below is my code...



[HTML]<html>
<head>
<base/>
<link rel="stylesheet" type="text/css" href="includes/css/vzsmb_popup_2008.css" />

<script language="JavaScript">

function addFromAddressBook()
{
var addrList = document.getElementById("names");
var options = new Object();
for(var j=0;j<addrList.options.length;j++)
{
if(addrList.options[j].selected)
{
var i = parseInt(document.getElementById( "iCheckboxes" ).value);
var cb = document.createElement( "input" );

cb.type = 'checkbox';
cb.id = "id" + i;
cb.name = "chkName" + i;
cb.value = "test" + i;

var text = document.createTextNode(addrList.options[j].text);
document.getElementById( 'participantDiv' ).appendChild( cb );

document.getElementById( 'participantDiv' ).appendChild( text) ;
cb.setAttribute('checked',true);



document.getElementById( "iCheckboxes" ).value = parseInt(document.getElementById( "iCheckboxes" ).value) + 1;

}
}
}


</script>
<body>
<form>
<div id="participantDiv" style="height:300px; overflow:auto; border:1px solid #CCC;font-size:9pt;" >



</div>


<input type="hidden" value="1" name="iCheckboxes" id="iCheckboxes">

<div style="height:150px; overflow-y: scroll;padding-left:10px;">
<select id="names" multiple="true" size="5" style="width:375px">
<option value="jam">jam@gmail.com</option>
<option value="kany">kany (keny@verizon.com)</option>
<option value="amy">amy (amy@verizon.com)</option>
<option value="aashi">aish (aish@gmail.com)</option>
<option value="jason">Jason (Jasom@gmail.com)</option>
<option value="Alice">Alice(Alice@gmail.com)</option>
<option value="Emily">Emily(Am@gmail.com)</option>
<option value="Rita">Rita(rita@gmail.com)</option>
<option value="Shiela">Shiela(ma@gmail.com)</option>
<option value="Noni">Noni(nonu@gmail.com)</option>
</select>

<input type="button" value="AddFromSelect" onclick="addFromAddressBook()">


</div>
</form>[/HTML]
Sep 17 '08 #1
7 2369
acoder
16,027 Expert Mod 8TB
The simple solution would be to remove the selected options each time.

PS. please use code tags when posting code.
Sep 17 '08 #2
afaheem
10
I need to check if the selected item is already available in the div and then not allow the user to add it again...any suggestions on how to proceed ?
Sep 18 '08 #3
acoder
16,027 Expert Mod 8TB
I know, but I suggested a very simple solution to the problem.

Remove the options that have been selected as you create the items, so that the user can now no longer selected them.
Sep 18 '08 #4
afaheem
10
I need to keep the options ..it should be a copy of what I am selecting ....removing the selected items is not what I want
Sep 18 '08 #5
acoder
16,027 Expert Mod 8TB
Ok, then keep an array of the items already selected. In the addFromAddressBook() function, check that none of the currently selected items are in the array. If they are, don't allow the user to add the selection. If validation passes and the items are added, add these newly selected options to the array.
Sep 18 '08 #6
afaheem
10
Ok, then keep an array of the items already selected. In the addFromAddressBook() function, check that none of the currently selected items are in the array. If they are, don't allow the user to add the selection. If validation passes and the items are added, add these newly selected options to the array.
The solution works partially....it fails when I try to delete the selected items in the div . The items gets removed but when I try to add them back from the selectbox they dont get added 'cos I am maintaining a list of already selected items in the array.
Please suggestions needed
Sep 23 '08 #7
acoder
16,027 Expert Mod 8TB
You'd need to remove them from the array too when deleting.
Sep 24 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Mark | last post by:
When my form goes to a new record, I have a procedure that copies the last record added to the form's underlying table into the form. The intent is that a series of new records may have the same...
9
by: vbportal | last post by:
Hi, I would like to add BitArrays to an ArrayList and then remove any duplicates - can someone please help me forward. I seem to have (at leaset ;-) )2 problems/lack of understanding (see test...
4
by: Todd Perkins | last post by:
Hello all, surprisingly enough, this is my first newsgroup post, I usually rely on google. So I hope I have enough info contained. Thank you in advance for any help! Problem: I am getting...
2
by: news | last post by:
I just upgraded to PHP 4.4.2 on my Slackware 10.2 system. And Apache/mySQL/PHP all work great through a browser. No errors. But when I try to run a PHP script through the command line, which I...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
4
by: FangQ | last post by:
hi I am very new to mysql. I have a question about using the "on duplicate update" clause with insert command. my table "data" has two columns, field1 and field2, where field1 is the index...
3
by: rajeshkrsingh | last post by:
Hi friends, Step1- create table duplicate ( intId int, varName varchar(50) ) insert into duplicate(intId,varName) values(1,'rajesh') insert into duplicate(intId,varName) values(2,'raj12')...
2
by: raphael001 | last post by:
In my Visual Basic program I'm just trying to find duplicate values entered into an array from an inputbox, but i can't seem to get the coding right on the final part to check for duplicate values...
4
by: ramdil | last post by:
Hi All I have table and it have around 90000 records.Its primary key is autonumber field and it has also have date column and name, then some other columns Now i have problem with the table,as my...
4
by: AXESMI59 | last post by:
have a project in which I am entering Serial Numbers and Date codes into a Combo box. Serial numbers are all different. However, they could each have the same Date Code. Each Serial Number has a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.