Question: How do you set an alert to make sure that the user has selected a radio button as well as entered some amount of information

How do you set an alert to make sure that the user has selected a radio button as well as entered some amount of information into the contact details section. Below is the example html and javascript.

Pie Order Form

Make your Pie!







Contact Details





Return to Class Menu

var cake_prices = new Array();

cake_prices["Round6"]=20;

cake_prices["Round8"]=25;

cake_prices["Round10"]=35;

cake_prices["Round12"]=75;

var filling_prices= new Array();

filling_prices["None"]=0;

filling_prices["Lemon"]=5;

filling_prices["Custard"]=5;

filling_prices["Fudge"]=7;

filling_prices["Mocha"]=8;

filling_prices["Raspberry"]=10;

filling_prices["Pineapple"]=5;

filling_prices["Dobash"]=9;

filling_prices["Mint"]=5;

filling_prices["Cherry"]=5;

filling_prices["Apricot"]=8;

filling_prices["Buttercream"]=7;

filling_prices["Chocolate Mousse"]=12;

function getCakeSizePrice()

{

var cakeSizePrice=0;

var theForm = document.forms["cakeform"];

var selectedCake = theForm.elements["selectedcake"];

for(var i = 0; i < selectedCake.length; i++)

{

if(selectedCake[i].checked)

{

cakeSizePrice = cake_prices[selectedCake[i].value];

break;

}

}

return cakeSizePrice;

}

function getFillingPrice()

{

var cakeFillingPrice=0;

var theForm = document.forms["cakeform"];

var selectedFilling = theForm.elements["filling"];

cakeFillingPrice = filling_prices[selectedFilling.value];

return cakeFillingPrice;

}

function candlesPrice()

{

var candlePrice=0;

var theForm = document.forms["cakeform"];

var includeCandles = theForm.elements["includecandles"];

if(includeCandles.checked==true)

{

candlePrice=5;

}

return candlePrice;

}

function insciptionPrice()

{

var inscriptionPrice=0;

var theForm = document.forms["cakeform"];

var includeInscription = theForm.elements["includeinscription"];

if(includeInscription.checked==true){

inscriptionPrice=20;

}

return inscriptionPrice;

}

function calculateTotal()

{

var cakePrice = getCakeSizePrice() + getFillingPrice() + candlesPrice() + insciptionPrice();

var divobj = document.getElementById('totalPrice');

divobj.style.display='block';

divobj.innerHTML = "Total Price For the Pie $"+cakePrice;

}

function hideTotal()

{

var divobj = document.getElementById('totalPrice');

divobj.style.display='none';

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!