For some reason my variable is coming put with undefined. I have looked and looked and i am sure it is obvious but i cannot figure it out.
Can someone please tell me how much of an amateur move i am making
Code:<script type="text/javascript"> function addtube(){ var count = parseInt(document.getElementById("tube_count").value); var temp1 = document.getElementById("abcd"); //alert(temp1.rows.length); //alert(count);alert(temp1); temp1.insertRow(temp1.rows.length); temp1.rows.item(temp1.rows.length - 1).insertCell(0); var xx = temp1.rows.length -1 ; count = count+1; var sHTML = document.getElementById("Quote_req_lines").innerHTML; sHTML = sHTML.replace('name="Quote_req1"','name="Quote_req'+count+'"'); sHTML = sHTML.replace('id="Quote_req1"','id="Quote_req'+count+'"'); sHTML = sHTML.replace('name="remove_window1"','name="remove_window'+count+'"'); sHTML = sHTML.replace('id="remove_window1"','id="remove_window'+count+'"'); sHTML = sHTML.replace('onclick="remove(1);"','onclick="remove('+count+');"'); sHTML = sHTML.replace('name="height_feet1"','name="height_feet'+count+'"'); sHTML = sHTML.replace('id="height_feet1"','id="height_feet'+count+'"'); sHTML = sHTML.replace('name="height_inches1"','name="height_inches'+count+'"'); sHTML = sHTML.replace('id="height_inches1"','id="height_inches'+count+'"'); sHTML = sHTML.replace('name="width_feet1"','name="width_feet'+count+'"'); sHTML = sHTML.replace('id="width_feet1"','id="width_feet'+count+'"'); sHTML = sHTML.replace('name="width_inches1"','name="width_inches'+count+'"'); sHTML = sHTML.replace('id="width_inches1"','id="width_inches'+count+'"'); sHTML = sHTML.replace('name="flash_select1"','name="flash_select'+count+'"'); sHTML = sHTML.replace('id="flash_select1"','id="flash_select'+count+'"'); sHTML = sHTML.replace('name="select_color1"','name="select_color'+count+'"'); sHTML = sHTML.replace('id="select_color1"','id="select_color'+count+'"'); temp1.rows.item(temp1.rows.length-1).cells.item(0).innerHTML=sHTML; //alert(sHTML); //temp.rows.item(temp.rows.length-1).cells.item(0).innerHTML=sHTML; document.getElementById("tube_count").value = count; count ++; } function testing1(){ var tube_line_count = document.getElementById("tube_count").value; var GrandTotalTubes = 0; var TotalCost = 0; for(var i=1; i<=tube_line_count; i++){ var HeightFeet = document.getElementById("height_feet"+i).value; if(HeightFeet ==''){ HeightFeet = 0; } var HeightInches = document.getElementById("height_inches"+i).value; if(HeightInches ==''){ HeightInches = 0; } var TotalHeight = (parseFloat(HeightFeet)*12)+parseFloat(HeightInches)-5; // changed divide to multiply; // changed parseint to parse float to handle decimals; alert(HeightFeet + ' Height Feet'); var WidthFeet = document.getElementById("width_feet"+i).value; if(WidthFeet ==''){ WidthFeet = 0; } var WidthInches = document.getElementById("width_inches"+i).value; if(WidthInches ==''){ WidthInches = 0; } var TotalWidth = (parseFloat(WidthFeet)*12)+parseFloat(WidthInches)-5; // changed divide to multiply; // changed parseint to parse float to handle decimals; TotalLength = (TotalHeight + TotalWidth)*2; // corrected to multiply both values * 2; alert(TotalLength + ' Total Length'); var TotalHeightTubes = Math.ceil(TotalHeight/48); // changed round to ceil to round the figure up; var TotalWidthTubes = Math.ceil(TotalWidth/48); // changed round to ceil to round the figure up; var TotalTubes = (TotalWidthTubes + TotalHeightTubes)*2; // corrected to multiply values *2; var HeightTubeSize = TotalHeight/TotalHeightTubes; var WidthTubeSize = TotalWidth/TotalWidthTubes; alert(TotalHeight + ' Total Height'); alert(TotalWidth + ' Total Width'); alert(TotalHeightTubes +' Total Height Tubes'); alert(TotalWidthTubes +' Total Width Tubes'); alert(TotalTubes +' Total Tubes'); var GrandTotalTubes = GrandTotalTubes+TotalTubes; alert(GrandTotalTubes +' Grand Total Tubes'); var TransformerLoadLength = (Math.ceil(TotalLength/12))+TotalTubes; // changed round to ceil to round the figure up; alert(TransformerLoadLength +' Transformer Load Length'); var Tranformer_load_value = document.getElementById("Transformer_Load").value; var myString = new String(Tranformer_load_value); var myArray_trans_load = myString.split(','); alert(Tranformer_load_value + ' Transformer load value'); alert(myString + ' My String'); alert(myArray_trans_load[0] + ' My Array 1'); alert(myArray_trans_load[1] + ' My Array 2'); //alert(myArray[1] + ' My Array'); var variable1 = TransformerLoadLength/myArray_trans_load[0]; var variable1RoundUp = Math.ceil(variable1); // changed round to ceil to round the figure up; var variable2 = TransformerLoadLength/myArray_trans_load[1]; var variable2RoundUp = Math.ceil(variable2); // changed round to ceil to round the figure up; //alert(variable1 + ' variable1'); //alert(variable2 + ' variable2'); alert(variable1RoundUp + 'variable1 rounded'); alert(variable2RoundUp + 'variable2 rounded'); var Transformertype_field_value = document.getElementById("Transformer_Type").value; var myString1 = new String(Transformertype_field_value); var myArray_trans_type = myString1.split(','); //alert(myArray_trans_type[0]); if(variable1RoundUp <= variable2RoundUp){ var TranformerType = myArray_trans_type[0]; } else{ var TranformerType = myArray_trans_type[1]; } //changed to round up to reflect correct calc alert(TranformerType + ' Transformer Type'); if(variable1RoundUp<variable2RoundUp){ var NumberOfTransformers = variable1RoundUp; } if(variable2RoundUp<variable1RoundUp){ var NumberOfTransformers = variable2RoundUp; } alert(NumberOfTransformers + ' Number of Transfomers'); var CostPerTube = document.getElementById("Cost_per_tube").value; var TubeSupportsPerTube = document.getElementById("Tube_Supports_per_tube").value; var CostPerTubeSupport = document.getElementById("Cost_per_Tube_Support").value; var GTOWirePerTube = document.getElementById("GTO_Wire_Per_Tube").value; var CostPerGTOWire = document.getElementById("Cost_per_GTO_wire").value; var EndCapsPerTube = document.getElementById("End_caps_per_Tube").value; var CostPerEndCap = document.getElementById("Cost_per_End_Cap").value; var Flashing_selected = document.getElementById("flash_select"+i).value; if(Flashing_selected == 'Yes'){ Flashing_upgrade_value = document.getElementById("Flashing_upgrade_cost").value; } else{ Flashing_upgrade_value = 0; } //alert(Flashing_upgrade_value); //we need to define the value. Because we don't have the value of this var Tranformer_field_value = document.getElementById("Transformer_Cost").value; var Transformer_Cost_Value = Tranformer_field_value.split(','); if(TranformerType == myArray_trans_type[0]){ var TransformerCost = Transformer_Cost_Value[0]; } else{ var TransformerCost = Transformer_Cost_Value[1]; } alert(TransformerCost + ' Transformer Cost'); var TotalCostWindow = parseFloat(TotalTubes*CostPerTube)+parseFloat(TotalTubes*TubeSupportsPerTube*CostPerTubeSupport)+parseFloat(TotalTubes*GTOWirePerTube*CostPerGTOWire)+parseFloat(TotalTubes*EndCapsPerTube*CostPerEndCap)+parseFloat(NumberOfTransformers*TransformerCost); //Replacing value to the total_cost field //document.getElementById("total_cost").value = TotalTubes; var TotalCost = TotalCost+TotalCostWindow; } //var TotalCost_RoundUp_Value = Math.round(TotalCost); document.getElementById("total_cost").value = TotalCost*2 + parseFloat(Flashing_upgrade_value); var TotalCartons = Math.ceil(GrandTotalTubes/8); } function remove(table_id){ if(table_id=='1'){ alert("Can't delete the row"); return; } document.getElementById("Quote_req"+table_id).style.display='none'; } </script>



Reply With Quote

Bookmarks