/    Sign up×
Community /Pin to ProfileBookmark

array using split()

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]);
}

}

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@awebbauthorJun 30.2003 — 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>
×

Success!

Help @awebb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...