1

I need some kind of textbox control that can host buttons along the text strings. Basically I want to create a textbox with names that enables the user to remove some names after addition. How can this be accomplished in javascript ?

Thanks in advance.

1 Answer 1

1

Just add SPANs before the textbox in your element. Format the SPANs as colored boxes with the text and maybe an X for deleting the entry and you're good to go.

Using JQuery this is really easy. Or do you want a Webforms-Control which is able to do that?

Edit:/

The Inline-Element could look like that:

<span id="my-filterbox">
  <input type="text" name="next-filter" />
</span>

And then your JS to add a key-event handler. Im using JQuery in this case:

$('#my-filterbox').keyup(function(event) {
  if(event.keyCode == '13') { // 13 = key code for enter
    var value = $(this).val();
    $(this).val('');
    $('#my-filterbox').prepend('<span class="filter-elem">' + value + '</span>');
  }
});

This way you add the filter to the span my-filterbox everytime the user hits enter. Per CSS you're able to format the span at the left side of the input box.

This code is untested but I think you get the idea.

Sign up to request clarification or add additional context in comments.

2 Comments

Do you mean to add those spans to the textbox ?
Thank you @schlingel that did the work, I used something similar to your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.