How to separate this string

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

    How to separate this string

    Hi forum, i'm a little new in javascript and maybe you can help me.

    I have an html form and an icon, if i click on the icon, a new pop-up
    window is open and shows a list of numbers with a structure like this
    :
    x.xx.xxx.xxxx.

    Now, this numbers are between an <a href> tag and if i clic on one of
    this, i call a javascript function, the idea is to put each one number
    separate for the "." in a textbox, so i did it before but putting it
    in a single input. Now i need to separate each one of this numbers and
    put it in each one of the textbox. If i have to put it in a single
    input i´ll do something like this:

    <script language="javas cript">
    function Funcion(val)
    {
    //val value is 1.12.123.1234
    window.parent.o pener.document. txtCtaNiv.value =val;
    top.parent.wind ow.close();
    }
    </script>

    The code above puts the value (that previosuly i selected in the popup
    window) in the input field of the main form. That's easy.

    Now if the parameter val has the value 1.12.123.1234 and in the main
    form i have four input fields called txtCtaNiv1, txtCtaNiv2,
    txtCtaNiv3, txtCtaNiv4, how can i separate the parameter val?, so i
    can put the 1 in txtCtaNiv1, the 12 in the input field txtCtaNiv2, the
    123 in txtCtaNiv3 and so on??

    Please if someone can give some example or idea will be great

    Thanls in advanced.
  • LJL

    #2
    Re: How to separate this string

    robert@disicom. com (Roberto Becerril) wrote in
    news:aea9a3db.0 402012248.1d8f8 40@posting.goog le.com:
    [color=blue]
    > Hi forum, i'm a little new in javascript and maybe you can help me.
    >
    > I have an html form and an icon, if i click on the icon, a new pop-up
    > window is open and shows a list of numbers with a structure like this
    >:
    > x.xx.xxx.xxxx.
    >
    > Now, this numbers are between an <a href> tag and if i clic on one of
    > this, i call a javascript function, the idea is to put each one number
    > separate for the "." in a textbox, so i did it before but putting it
    > in a single input. Now i need to separate each one of this numbers and
    > put it in each one of the textbox. If i have to put it in a single
    > input i´ll do something like this:
    >
    > <script language="javas cript">
    > function Funcion(val)
    > {
    > //val value is 1.12.123.1234
    > window.parent.o pener.document. txtCtaNiv.value =val;
    > top.parent.wind ow.close();
    > }
    > </script>
    >
    > The code above puts the value (that previosuly i selected in the popup
    > window) in the input field of the main form. That's easy.
    >
    > Now if the parameter val has the value 1.12.123.1234 and in the main
    > form i have four input fields called txtCtaNiv1, txtCtaNiv2,
    > txtCtaNiv3, txtCtaNiv4, how can i separate the parameter val?, so i
    > can put the 1 in txtCtaNiv1, the 12 in the input field txtCtaNiv2, the
    > 123 in txtCtaNiv3 and so on??
    >
    > Please if someone can give some example or idea will be great
    >
    > Thanls in advanced.
    >[/color]

    var dummy = val.split('.');
    document.getEle mentById('txtCt aNiv1').value = dummy[0];
    document.getEle mentById('txtCt aNiv2').value = dummy[1];
    document.getEle mentById('txtCt aNiv3').value = dummy[2];
    document.getEle mentById('txtCt aNiv4').value = dummy[3];



    The "split" method breaks up a string based upon a character in that
    string. In this case, the period between the numbers. It then puts those
    parts of the original string into an array, in this case "dummy".

    You may need to modify the "document.getEl ementById" sections to use the
    form name and elements names, but it should be something similar.

    Good luck, LJL

    Comment

    • Dr John Stockton

      #3
      Re: How to separate this string

      JRS: In article <aea9a3db.04020 12248.1d8f840@p osting.google.c om>, seen
      in news:comp.lang. javascript, Roberto Becerril <robert@disicom .com>
      posted at Sun, 1 Feb 2004 22:48:15 :-
      [color=blue]
      >Now if the parameter val has the value 1.12.123.1234 and in the main
      >form i have four input fields called txtCtaNiv1, txtCtaNiv2,
      >txtCtaNiv3, txtCtaNiv4, how can i separate the parameter val?, so i
      >can put the 1 in txtCtaNiv1, the 12 in the input field txtCtaNiv2, the
      >123 in txtCtaNiv3 and so on??[/color]


      The following, executed in <URL:http://www.merlyn.demon.co.uk/js-
      quick.htm> with the Eval button, puts the four substrings in the F.Xn
      controls.

      S = "1.12.123.1 234"
      T = S.split('.')
      for (J=0 ; J<4 ; J++) F.elements["X"+J].value = T[J]

      You should be able to adapt it.

      --
      © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
      <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
      <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
      <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

      Comment

      • Roberto Becerril

        #4
        Re: How to separate this string

        Thanks a lot for the help, it was just what i needed!!


        LJL <none@nowhere.c om> wrote in message news:<Xns948322 5165DAEnonenowh erecom@207.69.1 54.205>...[color=blue]
        > robert@disicom. com (Roberto Becerril) wrote in
        > news:aea9a3db.0 402012248.1d8f8 40@posting.goog le.com:
        >[color=green]
        > > Hi forum, i'm a little new in javascript and maybe you can help me.
        > >
        > > I have an html form and an icon, if i click on the icon, a new pop-up
        > > window is open and shows a list of numbers with a structure like this
        > >:
        > > x.xx.xxx.xxxx.
        > >
        > > Now, this numbers are between an <a href> tag and if i clic on one of
        > > this, i call a javascript function, the idea is to put each one number
        > > separate for the "." in a textbox, so i did it before but putting it
        > > in a single input. Now i need to separate each one of this numbers and
        > > put it in each one of the textbox. If i have to put it in a single
        > > input i´ll do something like this:
        > >
        > > <script language="javas cript">
        > > function Funcion(val)
        > > {
        > > //val value is 1.12.123.1234
        > > window.parent.o pener.document. txtCtaNiv.value =val;
        > > top.parent.wind ow.close();
        > > }
        > > </script>
        > >
        > > The code above puts the value (that previosuly i selected in the popup
        > > window) in the input field of the main form. That's easy.
        > >
        > > Now if the parameter val has the value 1.12.123.1234 and in the main
        > > form i have four input fields called txtCtaNiv1, txtCtaNiv2,
        > > txtCtaNiv3, txtCtaNiv4, how can i separate the parameter val?, so i
        > > can put the 1 in txtCtaNiv1, the 12 in the input field txtCtaNiv2, the
        > > 123 in txtCtaNiv3 and so on??
        > >
        > > Please if someone can give some example or idea will be great
        > >
        > > Thanls in advanced.
        > >[/color]
        >
        > var dummy = val.split('.');
        > document.getEle mentById('txtCt aNiv1').value = dummy[0];
        > document.getEle mentById('txtCt aNiv2').value = dummy[1];
        > document.getEle mentById('txtCt aNiv3').value = dummy[2];
        > document.getEle mentById('txtCt aNiv4').value = dummy[3];
        >
        >
        >
        > The "split" method breaks up a string based upon a character in that
        > string. In this case, the period between the numbers. It then puts those
        > parts of the original string into an array, in this case "dummy".
        >
        > You may need to modify the "document.getEl ementById" sections to use the
        > form name and elements names, but it should be something similar.
        >
        > Good luck, LJL[/color]

        Comment

        Working...