Adding a default text to the beginning of an text area - The Koch Family
The Koch Family The Koch Family

Latest news

جاري التحميل ...

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:

http://jsfiddle.net/SEXAj/2130/

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

http://jsfiddle.net/sarbbottam/TUc94/

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

+ Tag "span": http://jsfiddle.net/4YzZy/
+ Tag "div": http://jsfiddle.net/215b34fs/

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

References:
[1]. http://stackoverflow.com/questions/24846041/how-do-i-add-a-default-text-to-the-beginning-of-an-html-text-area
[2]. http://stackoverflow.com/questions/24305200/how-to-enable-to-insert-spaces-in-masked-input-plugin-jquery-plugin

Comments



If you like the content of our blog, we hope to stay in constant communication, just enter your email to subscribe to the blog's express mail to receive new blog updates, and you can send a message by clicking on the button next ...

إتصل بنا

About the site

author The Koch Family <<  Welcome! I'm so glad that you stopped by Your Modern Family blog. Together, we will talk about raising kids, organizing the home and saving money! and Tips & tricks and more…

< Learn more ←

Blog stats

Sparkline 2513183

All Copyrights Reserved

The Koch Family

2020