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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob

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

    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?
  • Lasse Reichstein Nielsen

    #2
    Re: Big help needed - Deleting specific values from textfield...

    djsphynx@hotmai l.com (Rob) writes:
    [color=blue]
    > Now say that the user wants to remove content2, without removing the
    > rest, how could I go about doing this?[/color]

    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("c ontent2, ").join("") ;

    or

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

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Evertjan.

      #3
      Re: Big help needed - Deleting specific values from textfield...

      Rob wrote on 08 mei 2004 in comp.lang.javas cript:
      [color=blue]
      > 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?[/color]

      if content1,2,3 do not contain comma's:


      Click on the following:
      <div onclick="remove center(this)">
      content1, content2, content3
      </div>

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

      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress)

      Comment

      Working...