Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 7th, 2007, 01:33 AM
Authorized User
 
Join Date: Aug 2006
Location: Mumbai, Maharastra, India.
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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


  #2 (permalink)  
Old February 7th, 2007, 02:15 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

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.
  #3 (permalink)  
Old February 7th, 2007, 05:29 AM
Authorized User
 
Join Date: Aug 2006
Location: Mumbai, Maharastra, India.
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

  #4 (permalink)  
Old February 16th, 2007, 06:32 AM
Registered User
 
Join Date: Feb 2007
Location: Chandigarh, UT, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to balpreet.patil Send a message via Yahoo to balpreet.patil
Default

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Placing database items into a list box hookenbook Visual Basic 2005 Basics 2 January 14th, 2009 08:56 PM
put mailto: links on list items in a combo box? webwolf Flash (all versions) 0 September 12th, 2008 08:01 AM
Moving Selected Items from a list box to excel AlanAtMars SQL Server 2000 2 August 19th, 2005 02:02 PM
Choosing Multiple Items in a List Box HenryE Access 1 July 25th, 2005 07:14 AM
list box 2 show items according 2 current variable warrenb24 ADO.NET 0 December 20th, 2004 12:01 PM





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