Click to See Complete Forum and Search --> : tied up with string


awebb
06-30-2003, 10:32 AM
I'm all tied up with a string problem (ho, ho, ho. poor humour, sign of nearing the edge).

I am geting sequential values from a <select> by looping through and basicaly adding to the [i] value to populate 4 text boxes with the options.

What I would like to do AT THE SAME TIME is have a lookat the values using split(), see if the month name is there and populate another series of text boxes with prices based on the month name.

I can do it if I artificially put the string in and split() it into an array but I can't seem to find a way to pull the value thats created while its looping through the selection.

Any help or pointers gratefully recived.
Andy

Heres the script:

<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="JavaScript">
<!--
function selectedDate(selection, form)
{
var dateSelection1="";
var dateSelection2="";
var dateSelection3="";
var dateSelection4="";
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 myString=form1.textbox1.value;/*This is the one I can't seem to get right*/
var myStringArray=myString.split(',');

for (var i=0;i<form1.weeks.length;i++)
{
if (form1.weeks.options[i].selected)
{
dateSelection1=form1.weeks.options[i].value;
}
if (form1.weeks.options[i].selected)
{
dateSelection2=form1.weeks.options[i+1].value;
}
if (form1.weeks.options[i].selected)
{
dateSelection3=form1.weeks.options[i+2].value;
}
if (form1.weeks.options[i].selected)
{
dateSelection4=form1.weeks.options[i+3].value;
}
}
form1.textbox1.value=dateSelection1;
form1.textbox2.value=dateSelection2;
form1.textbox3.value=dateSelection3;
form1.textbox4.value=dateSelection4;

if (myStringArray[1]==" June")
{
form1.price1.value=priceArray[1];
}
}

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

<body>
<form id="form1" action="" onsubmit="" >

<table width="100" border="0">
<tr>

</tr>
</table>
<table width="600" border="0">
<tr>
<td width="100">&nbsp;</td>
<td width="100"><select name="weeks" size="4" >
<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>
<option value="Sat, July, 12, 2003,">Sat, July, 12, 2003,</option>
<option value="Sat, July, 19, 2003,">Sat, July, 19, 2003,</option>
<option value="Sat, July, 26, 2003,">Sat, July, 26, 2003,</option>
<option value="Sat, August, 02, 2003,">Sat, August, 02, 2003,</option>
</select></td>
<td width="100">&nbsp;</td>
<td width="100">&nbsp;</td>
<td width="100">&nbsp;</td>
<td width="100">&nbsp;</td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td width="100"><input type="button" name="Choose" value="Choose week/s" onclick="selectedDate(this.form)" /></td>
<td width="100"><input name="textbox1" type="text" value="" size="20" /></td>
<td width="100" align="right"><input name="price1" type="text" id="price1" size="5" /></td>
<td width="100">&nbsp;</td>
<td width="100">&nbsp;</td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td width="100">&nbsp;</td>
<td width="100"><input name="textbox2" type="text" id="textbox2" value="" size="20" /></td>
<td width="100" align="right"><input name="price2" type="text" id="price2" size="5" /></td>
<td width="100">&nbsp;</td>
<td width="100">&nbsp;</td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td width="100">&nbsp;</td>
<td width="100"><input name="textbox3" type="text" id="textbox3" size="20" /></td>
<td width="100" align="right"><input name="price3" type="text" id="price3" size="5" /></td>
<td width="100">&nbsp;</td>
<td width="100">&nbsp;</td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td width="100">&nbsp;</td>
<td width="100"><input name="textbox4" type="text" id="textbox4" size="20" /></td>
<td width="100" align="right"><input name="price4" type="text" id="price4" size="5" /></td>
<td width="100" align="right"><input name="totalprice" type="text" id="totalprice" size="5" /></td>
<td width="100">&nbsp;</td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td width="100">&nbsp;</td>
<td width="100">&nbsp;</td>
<td width="100">&nbsp;</td>
<td width="100">&nbsp;</td>
<td width="100">&nbsp;</td>
</tr>
</table>
<p>&nbsp;</p>
</form>

</body>
</html>

Charles
06-30-2003, 05:43 PM
If you're up for changing the value of your "value" attributes then just use a valid date format and the Date object. You can even use a date format that doesn't involve so much typing.

<option value="2003-05-14">Sat, June, 14, 2003</option>

var then = new Date(document.formName.selectName.options[sel.selectedIndex].value);
['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][then.getDay()] // day name
['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][[then.getMonth()] // month name
then.getDate() // day number
then.getFullYear() // year