Avatar of jazz__man
jazz__man
 asked on

Listbox with item added via javascript loses its value.

Hi,

I have the following code ...
<script language="javascript" type="text/javascript">
    function openbrWindow() {
        var RetVal = window.showModalDialog("Popup/popupFrame.aspx?qs=../Pickers/TestForm.aspx",
        'PopupPage',
        'dialogHeight=300px;dialogWidth=700px,toolbar=no,unadorned=yes,directories=no,status=no,menubar=no,scrollbars=no,resizable=no ,modal=yes',
        '',
        true);

        var LstItems = document.getElementById("<%= lstItems.ClientID %>");

        var opt = LstItems.options;
        opt[opt.length] = new Option(RetVal, 1);

    }
</script>
<table>
<tr>
<td>
<asp:ListBox ID="lstItems" Width="400px" Height="37px" runat="server"></asp:ListBox>
</td>
<td>
<asp:Button ID="btnPick" runat="server" Width="40px" Height="40px" Text="" />
</td>
</tr>
</table>


The code above adds an item to a listbox but then in a split second the text disappears from the listbox. How can I get the text to stay in the listbox? Or why is this happening? Your help would be appreciated.

Thanks
ASP.NET.NET ProgrammingJavaScript

Avatar of undefined
Last Comment
jazz__man

8/22/2022 - Mon
Sudhindra A N

try..

var LstItems = document.getElementById("<%= lstItems.ClientID %>");
var newOpt= document.createElement("option");
newOpt.value=1;
newOpt.text=RetVal;
 LstItems.appendChild(newOpt);
ASKER CERTIFIED SOLUTION
jazz__man

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
jazz__man

ASKER
Found answer myself
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy