Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Splitting

Status
Not open for further replies.

newbby

Programmer
Mar 16, 2004
36
US
Hi,
I have the value from the select box as
<select name="somename">
<option value="123,myname,mynumber">Myself</option>
</select>
How can I spilt the value="123,myname,mynumber" into 3 variables using javascript. All I know is that the "somename" has 3 information separated by comma. Although I donot know the exact position of the comma.
var1 = 123
var2 = myname
var3= mynumber.
Thanks
 
Here's a very basic example:

Code:
<html>

<head>
<script language="javascript">
<!--
function doSplit(theVal) {
    var vals;
    alert(theVal);
    vals = theVal.split(",");
    alert(vals[0]);
    alert(vals[1]);
    alert(vals[2]);
}
-->
</script>

<body onload="doSplit('John Doe,24,New York');">
Here.
</body>
</html>

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top