开发者

HTML virtual soda vending machine

开发者 https://www.devze.com 2022-12-12 20:31 出处:网络
I am creating a virtual soda vending machine, and I am having issues with the html part of the virtual soda vending machine.

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.

I want to know if there is a better way to set this form up.

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>

Happy thanksgiving, and I am thankful for stackoverflow and the tremendous help you guys provide, thank your for not flaming the newb.


Except for the mispelling of "Nickel", the form looks fine to me. Just add up the variables from the form submission and use a Switch.

 $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;
 }

I'm not sure if this is exactly what you were asking, if you were more specific, I answer better.


The only way I would set up that form differently is to have some of the checks done in JavaScript beforehand. Other than that, it's set up as well as any other method.

0

精彩评论

暂无评论...
验证码 换一张
取 消