How to separate this string

  • Thread starter Roberto Becerril
  • Start date
R

Roberto Becerril

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="javascript">
function Funcion(val)
{
//val value is 1.12.123.1234
window.parent.opener.document.txtCtaNiv.value=val;
top.parent.window.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.
 
L

LJL

(e-mail address removed) (Roberto Becerril) wrote in
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="javascript">
function Funcion(val)
{
//val value is 1.12.123.1234
window.parent.opener.document.txtCtaNiv.value=val;
top.parent.window.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.

var dummy = val.split('.');
document.getElementById('txtCtaNiv1').value = dummy[0];
document.getElementById('txtCtaNiv2').value = dummy[1];
document.getElementById('txtCtaNiv3').value = dummy[2];
document.getElementById('txtCtaNiv4').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.getElementById" sections to use the
form name and elements names, but it should be something similar.

Good luck, LJL
 
R

Roberto Becerril

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


LJL said:
(e-mail address removed) (Roberto Becerril) wrote in
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="javascript">
function Funcion(val)
{
//val value is 1.12.123.1234
window.parent.opener.document.txtCtaNiv.value=val;
top.parent.window.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.

var dummy = val.split('.');
document.getElementById('txtCtaNiv1').value = dummy[0];
document.getElementById('txtCtaNiv2').value = dummy[1];
document.getElementById('txtCtaNiv3').value = dummy[2];
document.getElementById('txtCtaNiv4').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.getElementById" sections to use the
form name and elements names, but it should be something similar.

Good luck, LJL
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top