locked
retrieve all items with css class onclick RRS feed

  • Question

  • User-663351365 posted

    Hi,

    I'm using the following autosuggest javascript widget (http://devthought.com/projects/jquery/textboxlist/) to allow the user to enter values into a text box, however instead of storing the values selected via the autosuggest in the textbox, the javascript writes them all asynchronously into a <ul> on the page.

    I wanted to use this rather than the asp.net ajax autosuggester as it had greater customisation so i have tried with that but i'd really like to use this if possible.

    i want to be able to get the values from this <ul> and then pass them to another page as a query string, however i dont know if i can do any sort of "get all values inside of ul" function in asp.net...

    I'll post some code to see if it helps explain the situation:



            <asp:TextBox ID="searchbox" runat="server" />
            
            <asp:Button ID="Button1" runat="server" Text="search" 
                onclick="Button1_Click1" />

             <asp:TextBox ID="SearchBox" runat="server" />

            
            <asp:Button ID="Button1" runat="server" Text="search" 
                onclick="Button1_Click1" />


    as soon as the user types into the SearchBox and selects a value from the autosuggest the following gets written to the page (in the background):


    <ul class="textboxlist-bits">
    <li class="textboxlist-bit>value 1</li>
    <li class="textboxlist-bit>value 2</li>
    </ul>


    i was hoping to use the following code behind:

        protected void Button1_Click1(object sender, EventArgs e)
        {
            Response.Write(SearchBox.Text.ToString());
            
        }

    but there is nothing in the SearchBox as it bypasses this and writes the values to the <ul>

    I'm completely stuck now so any help would be greatly appreciated! I was wondering if there was a way to get all of the text which has a certain css class and then put them into an array? Or any other way around this that you could think of!

    Many thanks in advance.


    Thursday, September 10, 2009 11:35 AM

Answers

  • User532898053 posted

    Hi,

    I was wondering if there was a way to get all of the text which has a certain css class and then put them into an array?

    If you are using jQuery script library then you can just do the following to loop through all elements of a certain class:

    $(".textboxlist-bit").each( function() {
            var element = this;
            // do something with element
        }
    

    You could easily loop through and either place the data in a hidden text box or post it back via a web service call. But, where are you getting the list from? Usually it would be the server that is providing the list in the first place and therefore you could collect it the list when you are building in server side. If it is hard coded on the form then again, you know the list already and could just match the list server side.


    BTW: your list is missing the end quote to the list item classes.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 10, 2010 8:13 AM

All replies

  • User532898053 posted

    Hi,

    I was wondering if there was a way to get all of the text which has a certain css class and then put them into an array?

    If you are using jQuery script library then you can just do the following to loop through all elements of a certain class:

    $(".textboxlist-bit").each( function() {
            var element = this;
            // do something with element
        }
    

    You could easily loop through and either place the data in a hidden text box or post it back via a web service call. But, where are you getting the list from? Usually it would be the server that is providing the list in the first place and therefore you could collect it the list when you are building in server side. If it is hard coded on the form then again, you know the list already and could just match the list server side.


    BTW: your list is missing the end quote to the list item classes.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 10, 2010 8:13 AM
  • User-663351365 posted

    Many thanks for your reply. I looked at an alternative solution in the end but i will definitely look at this and see if its a better option. Appreciate it.

    Wednesday, March 10, 2010 8:59 AM