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

R

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?
 
L

Lasse Reichstein Nielsen

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
 
E

Evertjan.

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top