Adding item/s to a dropdownlist

A

Anita C

Hi,
I have a dropdownlist on a webform amongst other controls. One of the items
in the dropdownlist is 'New Value'. If the user selects 'New Value', I want
a web form of a precise size and modal too, to help the user create a new
value and when the new entry is accepted (in the modal webform) the new
value is added to the dropdownlist. How do I achieve the above described ?
Any help will be greatly appreciated .
 
R

Rohit

Hi Anita,
I hope this helps.

//this function pops up a window where user can add a new item and on
clicking OK
the window is closed and the new item is added to the dropdownlist.

function show()
{
var retValue = "";
var aOp;
var indx;
var cmb = document.getElementById("cmbSelect");

if(cmb.value != "0")
return;

var dialogOptions = "help:no; resizable:yes;
dialogHeight:790px;dialogWidth:900px;";
retValue = window.showModalDialog("WebForm3.aspx",null,dialogOptions);

if(retValue != "")
{
aOp = document.createElement('OPTION');
eval('aOp.innerText="' + retValue + '"');
//Index is incremented by 1 for every new item added ,
//You can change it as per your requirements
indx = cmb.length+1;
eval('aOp.value="' + indx + '"');
cmb.insertBefore(aOp,cmb.item(indx-2));
}
}


Regards,
Rohit,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top