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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove text from Text Area

Status
Not open for further replies.

lllyxer

Programmer
Nov 22, 2006
22
US
I have a text area with comma delimited string.
Let's say it's: "New York, Paris , London," i would like to click on one of the word and get it removed from the text area.
So if i click on Paris, then it's going to be only " New York , London".
Is it possible to accomplish it in any way?

Thank you
 
Hi

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title></title>
<script type="text/javascript">
function rmitem(what)
{
  if (what.selectionStart!=what.selectionEnd) return
  var str=what.value
  var pos=what.selectionStart
  var from=str.lastIndexOf(',',pos)
  var to=str.indexOf(',',pos)
  if (from==-1) { from=0; if (to!=-1) to++ }
  if (to==-1) to=str.length
  what.value=str.substr(0,from)+str.substr(to)
}
</script>
</head>
<body>
<form action="#">
<p>
<textarea id="t" rows="25" cols="80" onclick="rmitem(this)">New York, Paris , London</textarea>
</p>
</form>
</body>
</html>

Feherke.
 
Thanks, but it doesn't look like it works.
The var pos=what.selectionStart returns "underfined".
Please take a look and thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top