Skip to main content


Showing posts with the label HTML

Adding a default text to the beginning of an text area

I have a text area where I can enter a SQL statement. The text "SELECT TOP 1" is used at the begining of the sql statement as a default prefix that can not be removed.

In order to archive this functionality, I found three options:

1. Use an inputMask and build a pattern for the entered text. We can use the prefix inside the text area:

2. Create an javascript event listener on event "input" and calculate to prevent the prefix is removed

3. Use another html tag like "div"/"span" that contains the prefix and calculate the suitable position

+ Tag "span":
+ Tag "div":

I chose the 3rd approach with tag "div" because it's the most easiest solution and suitable for me at that monment.