HTML sanal soda otomat

2 Cevap

I am creating a virtual soda vending machine, and I am having issues with the html part of the virtual soda vending machine.

I want the user to be able to select money via a drop down list so that when the value of money is selected we sent that value to a php script that will only do stuff if selection == cost, and if selection != cost, we don't give the user a soda, we just prompt him or her for more money or give him the option to get back his/her change.

Someone was telling me that there are problems on the current html form in terms of how the user is suppose to pay for their soda.

Ben bu form kurmak için daha iyi bir yolu olup olmadığını bilmek istiyorum.

The max value the machine will take is a dollar, and denominations are limited to Quarters, Dimes and Nickles. Any combination of selection != cost will be disregarded by the php script and will cause me to ask the user for a new combination, preferably one that selection == cost.

   <label><b>Quarters:</b></label>
<select name="quarters" >
  <option value="25">25c</option>
  <option value="50">50c</option>
  <option value="75">75c</option>
  <option value="100">$1.00</option>
</select>
<label><b>Dimes:</b></label>
<select name="dimes" >
  <option value="10">10c</option>
  <option value="20">20c</option>
  <option value="30">30c</option>
  <option value="40">40c</option>
  <option value="50">50c</option>
  <option value="60">60c</option>
  <option value="70">70c</option>
  <option value="80">80c</option>
  <option value="90">90c</option>
  <option value="100">$1.00</option>
 </select>
 <label><b>Nickles:</b></label>
<select name="nickles" >
  <option value="5">5c</option>
  <option value="10">10c</option>
  <option value="15">15c</option>
  <option value="20">20c</option>
  <option value="25">25c</option>
  <option value="30">30c</option>
  <option value="35">35c</option>
  <option value="40">40c</option>
  <option value="45">45c</option>
  <option value="50">50c</option>
  <option value="55">55c</option>
  <option value="60">60c</option>
  <option value="65">65c</option>
  <option value="70">70c</option>
  <option value="75">75c</option>
  <option value="80">80c</option>
  <option value="85">85c</option>
  <option value="90">90c</option>
  <option value="95">95c</option>
  <option value="100">$1.00</option>
 </select>

Mutlu şükran, ve ben, stackoverflow ve siz sağlamak muazzam yardım için şükrediyorum newb yanan değil için teşekkür ederiz.

2 Cevap

"Nikel" bir yanlış yazım dışında, formu bana gayet iyi görünüyor. Sadece formu gönderiminden değişkenleri toplayın ve bir anahtar kullanmak.

 $price = yourPrice;
 $amt = $_POST['quarters'] + $_POST['nickels'] + $_POST['dimes'];

 switch($amt){
      case < $price;
      //Less than price
      break;

      case > $price;
      //Greater than price
      break;

      case == $price;
      //Exact change
      break;
 }

Ben bu size daha spesifik olsaydı, ben daha iyi cevap, soran, tam olarak ne olup olmadığından emin değilim.

Ben farklı bu formu kurmak istiyorum tek yolu önceden JavaScript yapılan kontroller bazı sahip olmaktır. Bunun dışında, herhangi bir diğer yöntemi gibi ayarlanmış oluyor.