jquery - "if" statement in javascript & displaying result in label -


i have registration form customer selects desired package via dropdownlist. select whether wish avail of multiyear discount choosing yes or no radio buttons. if yes radio button selected, dropdownlist shown (using javascript) selection of years 1-3. i'm not familar @ javascript, , need next when customer selects year 1, 2, 3 multiyear discounts, calculate discount, , show in label beside dropdownlist or hide label if customer has selected no multiyear discounts.

here existing code: javascript hide yearly discount dropdownlist

<script type='text/javascript'>  $(function(){   $('#discountselection').hide();      $('#no').click(function(){         $('#discountselection').hide();     });      $('#yes').click(function(){         $('#discountselection').show();     });  });  </script> 

and here html code:

        <td width="343">package*</td>          <td colspan="4">          <select class="purple" name="package">              <option value="standard">standard - &euro;55 monthly</option>              <option value="premium" selected="selected">premium - &euro;99 monthly</option>              <option value="platinum">platinum - &euro;149 monthly</option>          </select>          </td>          <tr>          <td width="343">would avail of our multiyear discounts?*          <br />see <a href="#dialog" name="modal">pricing</a> more details          </td>          <td colspan="4">              <input name="discount" type="radio" id="yes" value="yes" />yes              <input name="discount" type="radio" id="no" value="no" checked="checked" />no<br />                <select name="discountselection" class="purple" id="discountselection">                  <option value="1" selected="selected">1 year</option>                  <option value="2">2 years</option>                  <option value="3">3 years</option>                </select>                            </td> 

this if statement need execute within javascript calculate price:

if package == "standard" && discountselection == "1" {     cost = 45 * 12;     //display cost in label }    elseif package == "standard" && discountselection =="2" {     cost = 45 * 24;      //display cost in label } elseif package == "standard" && discountselection =="3" {     cost = 45 * 36;     //display cost in label } elseif package == "premium" && discountselection =="1" {     cost = 85 * 12;      //display cost in label } elseif package == "premium" && discountselection =="2" {     cost = 85 * 24;     //display cost in label } elseif package == "premium" && discountselection =="3" {     cost = 85 * 36;     //display cost in label } elseif package == "platinum" && discountselection =="1" {     cost = 134 * 12;     //display cost in label  } elseif package == "platinum" && discountselection =="2" {     cost = 134 * 24;     //display cost in label } else package == "platinum" && discountselection =="3" {     cost = 134 * 36;     //display cost in label } 

i unsure how create if statement within javascript. if offer advice, help, or links tutorials me in this, i'd grateful.

i hope understood question correctly, you're trying display label costs if user selected value select box.

if can accomplish using change event (provided jquery).

$("#discountselection").change(function()  {      var product_cat = $("#package option:selected").val();      if(product_cat == "standard") {        product_prefix = 45;     } else if (product_cat == "premium") {        product_prefix = 85;     } else if (product_cat == "platinum") {        product_prefix = 134;     }      var selected_value = $("#discountselection option:selected").val();     var cost = product_prefix * (12 * selected_value);     $("#costlabel").val(cost); });  

but please aware should double check these values on server!


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -