Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1808316
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:14:47+00:00 2026-05-17T06:14:47+00:00

Note: I have a workaround to this problem, but I’d prefer to comma-separate the

  • 0

Note: I have a workaround to this problem, but I’d prefer to comma-separate the values as I describe below rather than separating them with spaces (which is what my workaround does).

I have an ASP.NET website that allows instructors to choose from a DropDownList of preset comments and apply these comments to students in their classes. I display the students and comments inside a GridView, and use a Label to display any comments that already exist in the database (removing them from the DropDownList in the process). When an instructor selects one of these comments and clicks a button, my jQuery function:

  1. Pulls the selected value and text out of the option (provided it isn’t the default option).
  2. Checks Label.children().length, and appends a “, ” to the text if it’s greater than zero.
  3. Creates a <span> tag with a hidden field containing the value and text.
  4. Appends the text inside the span.
  5. Closes the span.
  6. Attaches an onclick event to the span.
  7. Removes the original option from the DropDownList.

The span tag’s onclick event does the reverse of what I describe above — it pulls the value and text out and re-creates the option inside the drop-down menu. Additionally, it replaces strings like “, , ” with “, ” in the parent Label. I’ve found that when I replace these strings (which lie outside the spans I’ve attached the onclick events to) that the onclick events go away.

I’m familiar with .live(), but because each row in this GridView contains a unique reference to the particular student and class currently in use, I can’t know the values that each row needs to pass into the funciton ahead of time. Is there any solution to this problem other than my described workaround or re-attaching the onclick event?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:14:48+00:00Added an answer on May 17, 2026 at 6:14 am

    Here’s an idea: Wrap the commas in <span>s with some class like ‘separator’. Then, when you remove an item, you can check to see if it’s the first thing in the list, and if so, remove the subsequent seperator, and if not, remove the previous one. So we’ll say you have an html structure like so:

    <span id="myLabel">
        <span class="comment">You're great!</span><span class="separator">, </span><span class="comment">You're mediocre!</span><span class="separator">, </span><span class="comment">You suck!</span>
    </span>
    

    Here’s a click function that should remove the commas properly, while maintaining the onclick events:

    $('.comment').click(function() {
        //decide which comma to remove
        if ($(this).prevAll('.comment').size() == 0) {
            //this is the first comment, remove the next comma and this comment
            $(this).next('.separator').remove().end().remove();
        } else {
            //this is not the first comment, remove the previous comma and this comment
            $(this).prev('.separator').remove().end().remove();
        }
    });
    

    Here’s a live demo showing that this works: http://jsfiddle.net/yWet5/

    Sorry if I’ve misunderstood any part of your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NOTE: I have solved the majority of this problem but have run into a
I´ve already done some research on that problem, but I can´t find a workaround.
PLEASE NOTE, I have found a work around which actually works out better for
NOTE: I have read Routing From the Inside Out AND the Engine Yard blog
Note: I have almost no idea at all how batch file 'for' loops work.
Note: I have given up on compiling iPhone Apps without a developer certificate for
Note I have completely re-written my original post to better explain the issue I
I have a note and it has a certain number of attributes. It also
(Please note that I have seen a similar question on StackOverflow recently, however I
Note - I do not have access to a database and cannot use PHP,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.