awebb
06-16-2003, 08:43 AM
I want a price to be displayed in a text box based on the selection.
I can make the selection appear in the textbox (just as it is in the <select>) but I can't seem to get the price to show based on the month selected.
BTW I just change the onChange value in the <select> from "copy()" to "findMonth()" which is why there are two output textboxes and only one input <select>.
Here's the code:
<script language="JavaScript">
<!--
function copy(selection)
{
var form=document.getElementById("form1");
form.textbox.value=selection;
}
function findMonth(selection)
{
var monthArray;
monthArray=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var priceArray;
priceArray=new Array("250","350","450");
var form=document.getElementById("form1");
var selectedMonthArray=form.split(',');
if (selectedMonthArray[1]=="January")
{
form.textboxp.value=priceArray[0];
}
if (selectedMonthArray[1]=="June")
{
form.textboxp.value=priceArray[1];
}
}
//-->
</script>
</head>
<body>
<form id="form1" action="" onsubmit="" >
<p>
<select name="prices" onchange="findMonth(this.options[this.selectedIndex].value)">
<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="text" name="textbox"/>
<input type="text" name="textboxp" />
</p>
</form>
I can make the selection appear in the textbox (just as it is in the <select>) but I can't seem to get the price to show based on the month selected.
BTW I just change the onChange value in the <select> from "copy()" to "findMonth()" which is why there are two output textboxes and only one input <select>.
Here's the code:
<script language="JavaScript">
<!--
function copy(selection)
{
var form=document.getElementById("form1");
form.textbox.value=selection;
}
function findMonth(selection)
{
var monthArray;
monthArray=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var priceArray;
priceArray=new Array("250","350","450");
var form=document.getElementById("form1");
var selectedMonthArray=form.split(',');
if (selectedMonthArray[1]=="January")
{
form.textboxp.value=priceArray[0];
}
if (selectedMonthArray[1]=="June")
{
form.textboxp.value=priceArray[1];
}
}
//-->
</script>
</head>
<body>
<form id="form1" action="" onsubmit="" >
<p>
<select name="prices" onchange="findMonth(this.options[this.selectedIndex].value)">
<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="text" name="textbox"/>
<input type="text" name="textboxp" />
</p>
</form>