[Javascript] form array2 values

Shawn Milo shawn.milo at gmail.com
Wed May 4 09:27:55 CDT 2005


Here's my contribution. It allows you to display the price for any
item, and also to change that value in the array.

Shawn



-------------------------------------------------------------------------------------------
<form action="./test.html" method="post" id="testForm">

   <select name="drpProducts" onchange="showPrice(this.value)">
      <option value=""></option>
      <option value="0">Item 1</option>
      <option value="1">Item 2</option>
      <option value="2">Item 3</option>
   </select>

   <input type="text" name="txtPrice" id="txtPrice" value="0,00"
size="10" />&euro;
   <input type="button" id="changePrice" name="changePrice"
value="Update Price" onclick="updatePrice()" />


</form>

<script type="text/javascript>

   var arrayPrices = new Array();

   arrayPrices[arrayPrices.length] = '1,100'
   arrayPrices[arrayPrices.length] = '2,300'
   arrayPrices[arrayPrices.length] = '5,500'


   function showPrice(indexNum){

      if (indexNum){
         document.forms['testForm'].txtPrice.value = arrayPrices[indexNum];
      }else{
         document.forms['testForm'].txtPrice.value = '';
      }
   }

   function updatePrice(){

         arrayPrices[document.forms['testForm'].drpProducts.value] =
document.forms['testForm'].txtPrice.value;
         alert(document.forms['testForm'].txtPrice.value);
   }

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



More information about the Javascript mailing list