473,320 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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="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.
Jul 20 '05 #1
3 1851
LJL
ro****@disicom.com (Roberto Becerril) wrote in
news:ae*************************@posting.google.co m:
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
Jul 20 '05 #2
JRS: In article <ae*************************@posting.google.com> , seen
in news:comp.lang.javascript, Roberto Becerril <ro****@disicom.com>
posted at Sun, 1 Feb 2004 22:48:15 :-
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??

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.1234"
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.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #3
Thanks a lot for the help, it was just what i needed!!
LJL <no**@nowhere.com> wrote in message news:<Xn****************************@207.69.154.20 5>...
ro****@disicom.com (Roberto Becerril) wrote in
news:ae*************************@posting.google.co m:
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

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Jaime Wyant | last post by:
I know I've seen this somewhere, but can't seem to google it. Is there a way to use an alternate statement separator, other than the default ';'? jw
2
by: Stian | last post by:
Hi! I have made a form with two SELECT LIST-boxes where the first is dynmically filled when you enter the page, and then one can select multiple options from the list and move across to the...
3
by: harhaiko | last post by:
Hello, I have 4,4 million rows of data in one column. I want to search for a string in each line. There are random amount of characters before the string I want to find. The string starts with the...
2
by: ad | last post by:
I have a string vaiable like "1a3345"; How to separate the string into a char array or a string array just have on character per element?
28
by: kfrost | last post by:
I know this is probably simple but I have a C# form and the class for the form is called sbaSynch. I have a textbox name txtServerName. I'm creating a class to manipulate XML functions so I...
12
by: Ann Marinas | last post by:
Hi all, I would like to ask for some help regarding separating the asp.net webserver and the sql server. I have created an asp.net application for a certain company. Initially, we installed...
1
by: drec | last post by:
I have a very simple mysql/php script that is being used to store program keys in a db for multiple users. I would like to add the ability to send these string values to another application. In...
2
by: colleen1980 | last post by:
Hi: Can any one please tell me how do i separate city state and zip. I ask this question in previous post. But when the city name is in two words it mess up my values otherwise it works. ...
14
by: Lambda | last post by:
I'd like to create separate character pointers, pass them to a function to assign each one different value, and assign the pointers to an array. But when I try: #include <stdio.h> #include...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.