1

Please check the script below.

Dynamic form, so the script also dynamic, I have to calculate when the form data changes. during this i am getting some problem.

am getting the value from the variable Final_price1, Final_price2 .....,Final_price7, Final_price8 and then am calculating the total of those.

During this calculation, am concatenating the following concat("Final_price",i); to get the values of the above. This concatenated correctly, but the above variables values are not coming. I dont know why the values are not getting there. So check the script and update me.

function assign_body()
  {  
var a_7= document.getElementById("option[280]").value;
     var spl_7  = a_7.split("_");
     //alert(spl);
            var cr_7    = spl_7[1];
            var operator3_7 = cr_7.split("[");
            var symbol7 = operator3_7[0];
            var dtt_7 =  operator3_7[1];
            var myarr_7         = dtt_7.split("$");
            var symbol_st_7 = myarr_7[1];
            //alert(symbol_st);
            //alert(symbol_s);
            //var symbol_a      = symbol_s.split("(");
            //var symbol        = symbol_a[1];
            //alert(symbol); 
            var split_value_7 = myarr_7[1];
            //alert(split_value);
            var final_value_7   =symbol_st_7.split(".");
            var Final_price7    =final_value_7[0];





     var a_8= document.getElementById("option[281]").value;
     var spl_8  = a_8.split("_");
     //alert(spl);
            var cr_8    = spl_8[1];
            var operator3_8 = cr_8.split("[");
            var symbol8 = operator3_8[0];
            var dtt_8 =  operator3_8[1];
            var myarr_8         = dtt_8.split("$");
            var symbol_st_8 = myarr_8[1];
            //alert(symbol_st);
            //alert(symbol_s);
            //var symbol_a      = symbol_s.split("(");
            //var symbol        = symbol_a[1];
            //alert(symbol); 
            var split_value_8 = myarr_8[1];
            //alert(split_value);
            var final_value_8   =symbol_st_8.split(".");
            var Final_price8    =final_value_8[0];



    var j=8;

    var total_amount=0;
    for(var i=1; i<=j; i++)
    {

         final_prices=concat("Final_price",i);
        alert(final_prices);
         symbol_prices=concat("symbol",i);
        alert(symbol_prices);
            if(isNumber(final_prices)){
                alert("number");
                /*if(symbol_prices =='+') {
                        alert("plus");
                     var total_amount+=parseInt(original_prices)+parseInt(final_prices);
                     calculated_price_element.innerHTML=total_amount;
                     alert(total_amount);
                } else if(symbol_prices =='-') {
                        alert("minus");
                     var total_amount+=parseInt(original_prices)-parseInt(final_prices);
                     calculated_price_element.innerHTML=total_amount;
                      alert(total_amount);
                }*/
         //alert('test');

            }

        }

 }
  • Try breaking your code down into relevant sections and posting only the broken part here. – Brad M Mar 20 '13 at 17:29
  • create a fiddle and maybe someone then helps – theshadowmonkey Mar 20 '13 at 17:30
  • isnt you total amount a varibale created in the loop and getting destroyed after the function ends, when it should be static? – theshadowmonkey Mar 20 '13 at 17:31
  • If you're trying to get the values out of the variables using dynamic variable names, see this: http://stackoverflow.com/questions/15481174/how-can-i-concatenation-parameter-name-out-of-2-strings – bfavaretto Mar 20 '13 at 17:32
  • Hi guys...Thank for ur response comment...Hi @theshadowmonkey...yes i am getting total amount in that variable.... –  Mar 21 '13 at 04:37
  • Hi....@theshadowmonkey...I need to get value for concat("Final_price",i);....and further i execute in for loop...Is it possible? –  Mar 21 '13 at 04:43
  • Hi @theshadowmonkey....please provide some more answer....if its possible or not? –  Mar 21 '13 at 10:48

0 Answers0