p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   How can I set TextBox value from asp.net Listbox, (http://p2p.wrox.com/showthread.php?t=66509)

vishnu108mishra March 10th, 2008 04:25 AM

How can I set TextBox value from asp.net Listbox,
How can I set TextBox value from asp.net Listbox, because I popuplate asp.net Listbox through java script..
I tried it by calling the java script function onChange(and onSelectedIndexChange) event of list box, but event is not calling java script function

from here..

following is my code--

<div id="helptypediv" style="visibility: hidden; z-index:1">
                            <asp:ListBox ID="lstShowHistory" SelectionMode="Single" runat="server" Width="200px" Height="300px"


function setTextBoxValue(e)
            //var strListBoxName = document.getElementById('lstShowHistory');
            document.getElementById('txtUrlLink').value = e ; //strListBoxName.options[strListBoxName.selectedIndex].text ;

//;options[document.getElementById('lstShowHistory').selected Index].text;

the list box is popuplate on mouse over event on the text box...

txtUrlLink.Attributes.Add("onfocus", "ShowList();");

function ShowList()
   document.getElementById('helptypediv').style.visib ility='visible';return false;

function getCookie()
        var strListBox = document.getElementById('lstShowHistory');
        var ls1= document.cookie.split("=");
        if (ls1.length >1)
            var ls2 = ls1[1].split("|");
            var count = ls2.length;
            var strLink = "";
            var optionItem;

            //Clear the previous options from the list
            for(var lstCount = strListBox.options.length-1; lstCount>-1; lstCount--)
                strListBox.options[lstCount] = null;
            if(count >= 2 )
                for(var x = count-1; x>=0; x--)
                        var ls3=ls2[x];//[x].split("|");
                        strLink+= ls3;
                        optionItem = new Option(ls3, ls3, false, false);
                        strListBox.options[strListBox.length] = optionItem;

vishnu108mishra March 10th, 2008 06:11 AM

g is my code--
I have resolved my problem..

following is code..
in CS file i added this line ..
lstShowHistory.Attributes.Add("onchange", "ShowText();");

and by javascript I set the value of textbox, but it works only on by selecting item from mouse.
How can I select value from the listbox by arrow key of keyboard?? Have you any idea...
function ShowText()
    var txtMessage =

document.getElementById('lstShowHistory').options[document.getElementById('lstShowHistory').selected Index].text;//GetComboText(document.g

    document.getElementById('txtUrlLink').value = txtMessage;
    document.getElementById('helptypediv').style.visib ility='hidden';return false;

All times are GMT -4. The time now is 03:27 PM.

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