By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,529 Members | 1,826 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,529 IT Pros & Developers. It's quick & easy.

Big help needed - Deleting specific values from textfield...

P: n/a
Rob
Hi everyone,
I have a form that has several disabled text fields. In these text
fields, I have initial values. Next to each text field lies a "copy"
button. When clicked, the content of the disabled text field is
appended to the content of another textfield, the only one that isn't
disabled (therefore the user can copy content from the other text
fields, and also add what they want). I also have a remove button,
which clears the content of that one non-disabled text field.

Pretty easy so far.

Here's the problem. Imagine I copy the content from textfield 1 into
the blank text field, then do the same for textfield 2 and 3.

Between each "insert", I've added a comma. So the non-disabled
(active) text field would have the following content:
content1, content2, content3,

Now say that the user wants to remove content2, without removing the
rest, how could I go about doing this?
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
dj******@hotmail.com (Rob) writes:
Now say that the user wants to remove content2, without removing the
rest, how could I go about doing this?


Are you sure the value are disjoint, i.e., "content2" is not a substring
of any of the other texts?

In that case, you can do, e.g.,:

string = string.split("content2, ").join("");

or

var idx = string.indexOf("content2, ");
var len = "content2, ".length;
string = string.substring(0,idx)+string.substring(idx+len);

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2

P: n/a
Rob wrote on 08 mei 2004 in comp.lang.javascript:
So the non-disabled
(active) text field would have the following content:
content1, content2, content3,

Now say that the user wants to remove content2, without removing the
rest, how could I go about doing this?


if content1,2,3 do not contain comma's:
Click on the following:
<div onclick="removecenter(this)">
content1, content2, content3
</div>

<script>
function removecenter(x){
x.innerHTML=x.innerHTML.replace(/,[^,]*,/,",")
}
</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.