I'm working on a JavaScript based page that returns the cost of delivery, depending on what the user selects(Region, service(pre 12, etc) and weight). I have muddled my way through as I just don't know JS.
My questions are:
- Can I pass the variable between functions - as detailed in the script below?
- Once the above has been achieved, I need to process the variables to display the result, now I could do a massive ifelse, don't really want to because there will be some 30 odd possibilities. All required info is in a SQL DB so this would be my preferred choice but I'm not sure how to do this with JS, the whole Browser side, Server side issue. Would I need to pass the variables(as above) to PHP (once all 3 are set) to grab the data from the SQL DB? If so, I'm not sure how to do this.
If I do use PHP then the page will have to be reloaded, is it possible to get this to be seamless to the user, i.e., all their selections are still displayed?
function flag(nation, area) { this.nation = nation; var el = document.getElementById("desc"); el.innerHTML = 'The region you have selected is <b>' + area + '</b>'; document.getElementById("flag").innerHTML = '<img src="images/flags/' + nation + '.jpg">'; } function output(service) { this.service = service; var el = document.getElementById("service-desc"); el.innerHTML = 'You have selected a <b>' + service + '</b> service.'; document.getElementById("clock").innerHTML = '<img src="images/clock-' + service + '.png">'; } function result() { //get varibles(nation & serive) from functions above ~ not sure how to do this! //process varibles if (nation == "UK" && service == "Standard next day") { document.getElementById("result").innerHTML = '£9.99'; } else if (nation == "UK" && service == "Before 12pm") { document.getElementById("result").innerHTML = '£14.99'; } // etc,etc,etc.... else { document.getElementById("a1").innerHTML = ""; } }