views:

46

answers:

2

I have this response.write on my page

function roundthecon() {
document.write(Math.round(exchRate*Math.pow(10,2))/Math.pow(10,2));
}

But it is re-writing my whole page and replacing it with the rounded number is there any other way of doing this without it re-writing my page?

Thanks

Jamie

UPDATE

Full javascript

if (exchRate != "") {

function roundthecon() {
var value = Math.round(exchRate*Math.pow(10,2)) / Math.pow(10,2);
$('.tablenotes > p > strong ').append(value);
}

function addCommas(nStr) {
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
    x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}


            // When the document is loaded..
            $(document).ready(function(){


                    // Grab an array of the table cells
                    $('.evenprop table tr td:not(.title)').each(function(){

                            // Calculate the pound price
                            var v_euro = $(this).html();

                            if (v_euro != "N/A") {

                            var v_euro = v_euro.replace(/,/g,'');
                            var v_euro = v_euro.replace(/\u20AC/g, '');
                            var v_euro = v_euro.replace(/£/g, '');

                            var v_pound = Math.round(v_euro / exchRate);
                            v_pound = addCommas(v_pound);

                            // Create a new span element for the pound


                            // Insert it at the end of the table cell

                            if (exchRate == <%= Session("xch_dollar") %>) {
                            $(this).prepend("$");
                            }
                            if (exchRate == <%= Session("xch_ntl") %>) {
                            $(this).prepend("X");
                            }
                            if (exchRate == <%= Session("xch_euro") %>) {
                            $(this).append("&euro;");
                            }

                            var o_span = $('<span/>').html(' <span style="font-weight:normal;" id="exchRate">(&pound;' + v_pound + ')</span>');
                            $(this).append(o_span);

                            }
                    });

            });

            }
+4  A: 
function roundthecon() {
  var value = Math.round(exchRate*Math.pow(10,2)) / Math.pow(10,2);
  $('#some_element_id').text(value);
}

document.write is usually best to not use. It can do some strange things.

Squeegy
Thanks it works but I need to append it and it's giving me the value twice now? any idea?
Jamie Taylor
`$('#some_element_id').append(value);` Twice? Are you call it it twice?
Squeegy
please see my update above with my source code
Jamie Taylor
Hmm, well your original question was answered. As another to help you figure out this bug of yours. Otherwise this will be a mishmash of a ton of different answers for different questions...
Squeegy
A: 

try something like this

function roundthecon() {
    document.innerHtml+=(Math.round(exchRate*Math.pow(10,2))/Math.pow(10,2));
}
Stas