Hi Friends...
I want a non-editable text in textarea. In that textarea user can write but can't edit or delete the default one.
I uses attribute "readonly="yes"" and editable="false" but these tags make full text area non-editable which is not required.
I want the editable text area with non-editable default text.
I don't Know what should I do??
Please help....
Thanks in advance...

Dani AI

Generated

Short answer: a plain <textarea> cannot contain a partially immutable region — it is all editable or all read-only/disabled. That explains why and ended up with the whole control disabled and why proposed splitting the value into two fields and concatenating on submit. Two practical, commonly used alternatives that preserve the look-and-feel of a single control are below.

A workable modern approach is to replace the textarea with a contenteditable container and make the fixed portion a non-editable child. The prefix sits in a span with contenteditable="false" while the outer element is editable. On focus you programmatically place the caret after the prefix, and on submit you copy the combined text into a hidden field for the real form submission:

<div id="editor" contenteditable="true" style="white-space:pre-wrap;border:1px solid #ccc;padding:6px;">
  <span id="prefix" contenteditable="false">Fixed, non-editable text: </span>
  <span id="user"></span>
</div>

<input type="hidden" name="message" id="messageField">
// move caret after prefix when focused; on submit copy text into hidden input
// (use range/selection APIs and extract prefix+user textContent)

Alternative (more compatible): use two real form controls (a readonly prefix field or plain text element plus a normal textarea) and visually fuse them with CSS; then concatenate on the client or server. This is the simplest, most robust solution for forms that must work everywhere and for serverside validation.

Notes and cautions: contenteditable behavior differs from textarea (handles markup, requires sanitization, no native form binding), keyboard/navigation can vary across browsers, and client-side protections can be bypassed — always validate/repair the final value server-side. Test the chosen solution for accessibility and mobile keyboard behavior before shipping.

Recommended Answers

All 5 Replies

The attribute to use would be disabled.

http://www.w3schools.com/TAGS/att_textarea_disabled.asp

While w3schools.com is a joke to learn from, it's a good reference for a vast assortment of language attributes.

Please don't suggest any idea before know the actual requirement. Atleast you have to read the thread first properly. I do not want to diaabled whole text area..

commented: dont be rude, the one you PO is likely the one who will help you, until you p them off -3

<textarea rows="3" cols="25" disabled="disabled">sample text</textarea>

TRY

2 input fields, concatenated on the server onsubmit is far simpler than attempting the impossible

<input type='text' value='this text value is in hardcode or generated by the script when creating the page the user cant change it' name='oneway2doit1'>
<textarea name='oneway2doit2'>type your *** here</textarea>
$textarea=$_post['oneway2doit1'].$_post['oneway2doit2'];

Please don't suggest any idea before know the actual requirement. Atleast you have to read the thread first properly. I do not want to diaabled whole text area..

Uh, what? I read it correctly, but didn't think that's what you were going after. There is NO WAY to do it using text unless you use two different input fields on that page as almostbob suggested.

Well, there is one way, but it's not with HTML. You'd simply place a background image onto the text area and put padding on that area covered by the image so no one can write on it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.