Click to See Complete Forum and Search --> : array using split()


awebb
06-30-2003, 04:10 AM
I have sucessfully populated a textbox with the results of multiple chices in a list.
Now I want to turn those strings into an array using split() so that I can sort them.
The strings are all in the same format (Day, Month, dd, yyyy,)and separated by ','.
I am wondering if the fact that there is always a blank line at the top of the textbox is screwing it up?
Here is the script:

function selectedDate(form)
{
var dateSelection="";
for (var i=0;i<form1.prices.length;i++)
{
if (form1.prices.options[i].selected)
{
dateSelection+="\n"+form1.prices.options[i].value;
}
}
form1.textbox.value=dateSelection;
}

function seePrice(form)
{
var monthArray=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var priceArray=new Array("600","900","1000","1500");
var selectedMonthArray=form1.textbox.value.split(',');
if(selectedMonthArray[1]==" June")
{
form.price1.value=(priceArray[0]);
form.pricetotal.value=(priceArray[0]);
}

}

awebb
06-30-2003, 05:10 AM
I have realised it might make things easier if you could see the html as well.
Hope this helps...

<script language="JavaScript">
<!--
function selectedDate(form)
{
var dateSelection="";
for (var i=0;i<form1.prices.length;i++)
{
if (form1.prices.options[i].selected)
{
dateSelection+="\n"+form1.prices.options[i].value;
}
}
form1.textbox.value=dateSelection;
}

function seePrice(form)
{
var monthArray=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var priceArray=new Array("600","900","1000","1500");
var selectedMonthArray=form1.textbox.value.split(',');
if(selectedMonthArray[1]==" June")
{
form1.price1.value=(priceArray[0]);
form1.pricetotal.value=(priceArray[0]);
}

}
//-->
</script>
</head>

<body>
<form id="form1" action="" onsubmit="" >
<p>
<select name="prices" size="4" multiple="multiple" >
<option value="" >Please Choose</option>
<option value="Sat, June, 14, 2003,">Sat, June, 14, 2003</option>
<option value="Sat, June, 21, 2003,">Sat, June, 21, 2003</option>
<option value="Sat, June, 29, 2003,">Sat, June, 29, 2003</option>
<option value="Sat, July, 05, 2003,">Sat, July, 05, 2003</option>
</select>
<input type="button" name="Choose" value="Choose week/s" onClick="selectedDate(this.form1)" />
<textarea name="textbox" cols="30" rows="4"></textarea>
<input type="button" name="pricecalc" value="See Price" onClick"seePrice(this.form1)"/>
Price:&pound;</p>
<table width="100" border="0">
<tr>
<td><input name="price1" type="text" id="price1" size="5" /></td>
</tr>
<tr>

</tr>
<tr>
<td><input name="pricetotal" type="text" id="pricetotal" size="5" /></td>
</tr>
</table>
</form>

</body>
</html>