How do you split a string in JavaScript

C

Craig G

i have the little jscript which i use for returning a value from a
popupModal. but i want to extend this so that i cant split the string into
different values

in future the string will return a concatenated value, eg BT56FD%ClaraPark,
with % being the dividing marker. but not being compentent in jscript i am
unable to split the returned value

at the mo i have this:-
if (strReturn != null)
document.getElementById('txtPostcode').value=strReturn;

but i want this:-
if (strReturn != null)
document.getElementById('txtPostcode').value=<all data upto % marker>
document.getElementById('txtAddress').value=<all data after % marker>;

Cheers,
Craig

how do i go about this?
 
Y

Yunus Emre ALPÖZEN

Surely, It is possible just use split method...
sampleStr="ABC%123"
var strArray= sampleStr.split("%") // This function returns an array of
string
It is up to you to traverse this array with a loop
for(var i=0; i>strArray.length;i++)
{
///strArray
}
otherwise just use strArray[0], strArray[1] to access it..
 

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

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top