PDA

View Full Version : Change a string to an array


Steven_Smith
02-21-2005, 05:36 PM
Hello, I am trying to change a string into an array. If I were to do this with PHP I would $myarray=explode(",",$document.form1.air.value); Well kind of

I would like to the value of myarray to be 'A' (or b or c) but right now it is "A","38TDB","500","250","300". Is their a explode like function in javascript?

<form name="form1"
<select id="air" name="air" onchange="xxxx()">
<option label="a" value='"A","38TDB","500","250","300"'>A</option>
<option label="b" value='"B","38TDB","100","250","200"'>B</option>
<option label="c" value='"C","38TDB","500","550","300"'>C</option>
</select>
</form>
<script language="JavaScript1.2">
function xxxx(){
var myarray=document.form1.air.value;
alert(myarray[0]);
}
</script>

Thanks
Steve

Steven_Smith
02-21-2005, 06:17 PM
<form name="form1"
<select id="air" name="air" onchange="xxxx()">
<option label="a" value='"A","38TDB","500","250","300"'>A</option>
<option label="b" value='"B","38TDB","100","250","200"'>B</option>
<option label="c" value='"C","38TDB","500","550","300"'>C</option>
</select>
</form>
<script language="JavaScript1.2">
function xxxx(){
var myarray=document.form1.air.value;
var test=myarray.split(",");
alert(test[0]);
}
</script>

I added var test=myarray.split(","); So the PHP command explode is like the javascript command 'split'

Cool
Steve