Avoid duplicate record from dropdown Javascript PHP -
i have code this
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>eg - textbox dropdown</title> </head> <body> <input name="textboxexample" type="text" maxlength="50" id="textboxexample" tabindex="2" onchange="dropdownindexclear('dropdownextextboxexample');" style="width: 242px; position: absolute; top: 0px; left: 0px; z-index: 2;" /> <select name="dropdownextextboxexample" id="dropdownextextboxexample" tabindex="1000" onchange="dropdowntexttobox(this,'textboxexample');" style="position: absolute; top: 0px; left: 0px; z-index: 1; width: 265px;"> <option value="value item 1" title="title item 1">item 1</option> <option value="value item 2" title="title item 2">item 2</option> <option value="value item 3" title="title item 3">item 3</option> </select> <script language="javascript" type="text/javascript"> //since first <option> preselected indexclear function must fire once clear out. dropdownindexclear("dropdownextextboxexample"); </script> </div> </body> </html> <script type="text/javascript"> function dropdowntexttobox(objdropdown, strtextboxid) { document.getelementbyid(strtextboxid).value += objdropdown.options[objdropdown.selectedindex].value.concat(','); dropdownindexclear(objdropdown.id); document.getelementbyid(strtextboxid).focus(); } function dropdownindexclear(strdropdownid) { if (document.getelementbyid(strdropdownid) != null) { //document.getelementbyid(strdropdownid).selectedindex = -1; var x=document.getelementbyid("dropdownextextboxexample"); x.remove(x.selectedindex); } } </script> the code works fine, need avoid same record selected again , again.
for ex: if select item 1 dropdown should not selected again. in case, can select item 1 'n' number of times.
i need here.
thanks haan
<select name="dropdownextextboxexample" id="dropdownextextboxexample" tabindex="1000" onchange="dropdowntexttobox(this,'textboxexample');" style="position: absolute; top: 0px; left: 0px; z-index: 1; width: 265px;"> <option value="">select item</option> <option value="value item 1" title="title item 1">item 1</option> <option value="value item 2" title="title item 2">item 2</option> <option value="value item 3" title="title item 3">item 3</option> </select>
Comments
Post a Comment