When the user wanna add the text so the default value should be added
to the text all the time
You can add a default value to the text area by including the required text inside textarea
tags. However this text can be altered by the user. Consider the below snippet.
<textarea>I will</textarea>
In the above snippet you can simply delete the default text "I will" and insert your own text. Hence this is not a solution to your question.
Preferable and easiest solution
If a certain default value has to be added to the input text in <textarea>
all the time, you can position a <label>
over the <textarea>
as shown below. Alter the values of CSS properties as needed according to the styling of the project.
div{
position: realtive;
}
textarea {
padding-left: 50px;
}
label {
position: absolute;
top: 10px;
left: 15px;
}
<div>
<form action="submit.php" method="POST">
<textarea id="textarea" name="text_input"></textarea>
<label>I will</label>
</form>
</div>
Since you have added php
in the tags for the questions, assuming that you are using PHP in the back end, you can handle the input as follows.
Since we have added action="submit.php"
and method="POST"
to the form
tag in HTML markup, the form will be submitted to submit.php
script via POST
method. Also since we added name="text_input"
to the textarea
tag we can access it's value via $_POST['text_input']
. You can concatenate the default text in the back end as below.
$default_text = "I will"
//do the required validation and security checks
$form_text = $_POST['text_input']
$text_to_store = $default_text + $form_text
Then you can store and display $text_to_store
in your database.