javascript - Performing calculations on an html form -



javascript - Performing calculations on an html form -

i new html & javascript , have been assigned task create html form restaurant allows user input info booking. far have created form website , validated each input field in order ensure right info entered necessary fields. however, need enable form calculate total cost booking based on 2 details (number of people in party & if client wishes dine in vip area).

here related html code far:

... <strong>select party size:</strong> <br> <select name="party" id="party" onblur="validateselect(name)"> <option value="">please select</option> <option value="1">1 person (£5)</option> <option value="2">2 people (£10)</option> <option value="3">3 people (£15)</option> <option value="4">4 people (£20)</option> <option value="5">5 people (£25)</option> <option value="6">6 people (£30)</option> <option value="7">7 people (£35)</option> <option value="8">8 people (£40)</option> <option value="9">9 people (£45)</option> <option value="10+">10+ people (£50)</option> </select> ... <strong> vip area? </strong> <br> yes (+£5) <input type="radio" name="hand" id="left" value="yes"onblur="validateradio(id)"/> no <input type="radio" name="hand" id="right" value="no" onblur="validateradio(id)"/> <span class="validateerror" id="handerror" style="display: none;">please specify whether table in vip area.</span> ... <strong> total booking cost based on party size & vip selection: </strong>

for example, if client selects there 6 people in party , wish seated in vip area, total cost displayed @ bottom of page £35. understand can performed in javascript grateful if show me how can done. give thanks you!

try this

class="snippet-code-js lang-js prettyprint-override">$(document).ready(function(){ $(document).on('change', '#party', function(e) { $('#price').html(parseint($(this).val()) + parseint($('input[name="hand"]:checked').val())); }); $(document).on('click', 'input[name="hand"]', function(e) { $('#price').html(parseint($('#party').val()) + parseint($(this).val())); }); }); class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <strong>select party size:</strong> <br> <select name="party" id="party" onblur="validateselect(name)"> <option value="">please select</option> <option value="5">1 person (£5)</option> <option value="10">2 people (£10)</option> <option value="15">3 people (£15)</option> <option value="20">4 people (£20)</option> <option value="25">5 people (£25)</option> <option value="30">6 people (£30)</option> <option value="35">7 people (£35)</option> <option value="40">8 people (£40)</option> <option value="45">9 people (£45)</option> <option value="50">10+ people (£50)</option> </select> <strong> vip area? </strong> <br> yes (+£5) <input name="hand" id="left" value="5" onblur="validateradio(id)" type="radio"> no <input name="hand" id="right" value="0" onblur="validateradio(id)" checked="" type="radio"> <span class="validateerror" id="handerror" style="display: none;">please specify whether table in vip area.</span> <strong> total booking cost based on party size <span id="price">0</span> vip selection: </strong>

javascript html forms

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -