-1

I need the page to output a result once all the variables have been selected...

I am new to code and javascript so please don't grill me as I don't know where to begin in solving this one.

http://www.storageheaters.com/heat-loss-calculator.htm

philip
  • 1
  • 2
  • I'd make a bet that it's a server side problem. The original site probably does the calculations on their server, not on the client (javascript is client-side). You can't copy and paste their server code because you don't have access to it. You could try to routing input from your site through their server, that would require learning more about programming. – Alter Sep 25 '14 at 23:06
  • Thanks Alter, where in the Dimplex page below, does it make reference to the server side piece of code? http://www.dimplex.co.uk/products/commercial_heating/heat_loss_calculator.htm – philip Sep 26 '14 at 09:45
  • There's a function called xmlhttpPost in the linked http://www.dimplex.co.uk/schema/js/pagescript.js file. I don't think it's related to the calculations, but it maybe. It'd be a bit of a pain to unravel the whole thing – Alter Sep 27 '14 at 22:55
  • I would search around for things related to the "heatloss_calc" form on that calculate page, see if you can find anything that sends its data to another file. It has a submit button but I didn't see anything that stood out when I skimmed it – Alter Sep 27 '14 at 23:01

2 Answers2

0

"Have I referenced the Javascript files correctly on this html page?"

Yes, your JavaScript files are correctly referenced. Your css files aren't though (open the network tab of your chrome developer tools - or in any browser), you'll see http 404 responses (not found).

But I'm not sure your script works - well I can't say more since I don't know exactly what it's supposed to do ...

topheman
  • 6,374
  • 4
  • 20
  • 32
  • Thanks Tophe, I am trying to replicate this http://www.dimplex.co.uk/products/commercial_heating/heat_loss_calculator.htm I need it to output a recommendation of how much KW is required... on a new page. I've copied it exactly but it doesn't seem to function in the same way as the original. Nothing happens! – philip Sep 25 '14 at 21:47
0

Usually scripts are stored in file on your web server, and reference is included to head tag like

 <script type="text/javascript" src="your_script.js"></script>

You have to use that link to get more info Where should I put <script> tags in HTML markup?

Here is quick solution (it is not best one, but it works and is suitable for newcomers)

var theTemps = [18, 21, 16],
    theWallUValues = [0.45, 0.6, 0.8],
    theRoofUValues = [0.32, 0.6, 2],
    theWindowUValues = [1.6, 0.6, 2],
    theFloorUValues = [3.2, 6.4, 4.7],
    condition_array = [false, false, false, false, false]; // one for each field

function result(){
  alert('all are selected');
}

function check_if_all_are_full(){
    // call result function if all elements in array are true
    if (condition_array.every(function(element){return element;})){
        result();
    }
};

function i_am_selected(integer){
    // update array and call check if all are selected
    result[integer] = true; 
    check_if_all_are_full();
}

function setTemp(t) {
  i_am_selected(0);
  document.heatloss_calc.house_room_temp.value = theTemps[t];
}

function setHouseWallUValue(u) {
  i_am_selected(1);
  document.heatloss_calc.house_wall_u_value.value = theWallUValues[u];
}

function setHouseRoofUValue(u) {
  i_am_selected(2);
  document.heatloss_calc.house_roof_u_value.value = theRoofUValues[u];
}

function setHouseWindowUValue(u) {
  i_am_selected(3);
  document.heatloss_calc.house_window_u_value.value = theWindowUValues[u];
}

function setHouseFloorUValue(u) {
  i_am_selected(4);
  document.heatloss_calc.house_floor_u_value.value = theFloorUValues[u];
}

Also - it can be a good idea to make submit button inactive by default, and use result function to make it active (here is the link http://www.w3schools.com/jsref/prop_submit_disabled.asp)

Community
  • 1
  • 1
  • Thanks a lot Oleksii, which file should I deposit this code into? And where shall I make reference to it? Sorry for the dumb questions I am new to javascript... PS. i TRIED to upvote your answer but I dont have enough points!! – philip Sep 26 '14 at 09:48
  • It is fine) You just need to put the script to file with name "myscript.js", and to make sure, that Your web server can respond with that file on request (please, make sure that this part hardly depends on backend you use - in case if don't know what it is - just leave the script in its place and forget about what I told You)))), after that - You just need to place reference to your file in your head tag - if you take a look at your HTML - there are couple of scripts in head tag. Just place it behind last script. IF you find it unclear - just keep writing scripts like You do. It is not critica – oleksii.shyman Sep 26 '14 at 16:58