p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Professional (http://p2p.wrox.com/forumdisplay.php?f=57)
-   -   adding items to list box using javascript (http://p2p.wrox.com/showthread.php?t=53718)

k.manisha February 7th, 2007 01:33 AM

adding items to list box using javascript
 
hi friends


i have one text box in which i will enter some value

that value i want to add to list box

how can i do this


thanks



mike_remember February 7th, 2007 02:15 AM

Hi

You can use the JS function below to fullfil your requirement:

function AddItems()
        {
            var myForm = document.Form1; //Form Name
            var mySel = myForm.sel; // Listbox Name
            var myOption;

            myOption = document.createElement("Option");
            myOption.text = document.getElementById("txt").value; //Textbox's value
            myOption.value = document.getElementById("txt").value; //Textbox's value
            mySel.add(myOption);
        }

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.

k.manisha February 7th, 2007 05:29 AM

hi mike

thanks for reply

i tried it its working fine


but items of list box which i have added using javascript
 i am not able to refer in codebehind file


thanks


balpreet.patil February 16th, 2007 06:32 AM

hi..buddy...

As u have added list items in drop down, it fine but when we add list items using javascript we can't access those items in code behind.
so, solution to this problem is store dropdown's selected value or text whichever u need in some hidden server control at onChange event(java script) and read that value from that hidden control in your code behind.

if u still face any problem e-mail me at balpreet.patil@gmail.com

thanks..

Balpreet...

Balpreet Patil


All times are GMT -4. The time now is 11:12 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.