Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disabled textarea

Status
Not open for further replies.

mellenburg11

Programmer
Aug 30, 2004
9
US
I have a form that writes a text area field to a database. The field can get long so I'm using a textarea control for entry. When someone wants to add to this field, I want them to enter it in a new textarea control and I append the new string to the old string and write it to the database. I want it this way because I don't want the user to be able to modify past comments.

The problem is that when I disable the textarea, the information doesn't carry over when the form is submitted. How can I not allow a textarea field to be modified and keep the information?

I've tried making a hidden field with the value set to the previous textarea, but I think the presence of both single and double quotes is messing it up.
 
Take a look into the addslashes() function. It will escape any single or double quote in a string with the backslash character.

This may be useful in populating your hidden field.

*cLFlaVA
----------------------------
Ham and Eggs walks into a bar and asks, "Can I have a beer please?"
The bartender replies, "I'm sorry, we don't serve breakfast.
 
Sorry, that is assuming you're using PHP.

*cLFlaVA
----------------------------
Ham and Eggs walks into a bar and asks, "Can I have a beer please?"
The bartender replies, "I'm sorry, we don't serve breakfast.
 
mellenburg...

What happens if you use the readonly attribute instead of disabled?

Something I try not to do, but might work for you, is to enable the textarea at the time of submission (<form onsubmit="this.textareaName.disabled=false">).

--Dave
 
Netscape does not recognize readonly nor disabled.

*cLFlaVA
----------------------------
Ham and Eggs walks into a bar and asks, "Can I have a beer please?"
The bartender replies, "I'm sorry, we don't serve breakfast.
 
Does it recognize: contenteditable='false'? This also works in IE.

--Dave
 
Apparently not. MSIE only.

*cLFlaVA
----------------------------
Ham and Eggs walks into a bar and asks, "Can I have a beer please?"
The bartender replies, "I'm sorry, we don't serve breakfast.
 
if you must get into equivalents, try:

onFocus="blurIt(this)";

and then have
Code:
function blurIt(field)
{
  if (blur)
    field.blur();
}

Set blur to true if you want the field disabled, false otherwise.

--Chessbot

The program didn't do anything wrong; it did exactly what you told it to!
 
Netscape does not recognize readonly nor disabled.

Really? They're both standard W3C attributes. What version of Netscape are you talking about?

What I don't understand is why you need to disable any text areas. You have a control where people can enter some text to be appended to a database field, you (presumably) have some hidden field to identify the record to be updated, what more do you need? Just change your script to append the new text to whatever's already there - you don't need to send the current value up and down the line.

-- Chris Hunt
 
ChrisHunt-

Nice catch. Apparently I'm the idiot. I just tested them both in Netscape 7.2 and they work. Can someone tell me why I was under that assumption? Did they not work in earlier versions of Netscape? I know I've attempted both readonly and disabled before in Netscape, only to not have them work. Maybe another form field?

Thanks again for the correction ChrisHunt.

*cLFlaVA
----------------------------
Ham and Eggs walks into a bar and asks, "Can I have a beer please?"
The bartender replies, "I'm sorry, we don't serve breakfast.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top