0

I want to add the default value in the Textarea field

When the user wanna add the text so the default value should be added to the text all the time

Just like Fiverr when the user enters the title "I will" text add automatically https://prnt.sc/1qe1bbw

Thanks

Ruben
  • 319
  • 2
  • 14
  • Please elaborate your question, if it is about the default value for the `textarea` then this is a duplicate question as [This question](https://stackoverflow.com/questions/6007219/) , what I could understand was you want an `auto fill` feature when user enters the text right? – Mohammed Khurram Aug 24 '21 at 06:34
  • @MohammedKhurram He wants a default value to appear in the `textarea` all the time just like on [fIverr](https://prnt.sc/1qe1bbw). Adding a default value in the `textarea` can be changed by the user. – Rifky Niyas Aug 26 '21 at 06:41
  • @Muhammad Mazhar Iqbal did my solution work for you? You had replied that it ended up working for you and now that response seems to be deleted. Can you explain whether or not my solution is correct? If it is useful consider [upvoting and accepting the answer](https://stackoverflow.com/help/someone-answers) – Rifky Niyas Aug 27 '21 at 08:37

2 Answers2

1

Text inside textarea tags will be it (if I understood correctly) :

<textarea>Default text</textarea>
MetropolisCZ
  • 567
  • 1
  • 8
  • 20
-1

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.

Rifky Niyas
  • 1,737
  • 10
  • 25