Question

I'm missing something very basic here, I think!

$(function() {
    $('#zahlungsart_0').click(function() {
            var gesamtsumme_neu = Number($('#gesamtsumme').attr('rel'))+6;
            gesamtsumme_neu.toString;
            gesamtsumme_neu.replace('.',',');
            console.log(gesamtsumme_neu);
            $('#gesamtsumme').text(gesamtsumme_neu);
    });

Error: TypeError: gesamtsumme_neu.replace is not a function

Thanks in advance for any help!

Was it helpful?

Solution 4

toString is not a property, it's a function - toString(), thus should be called as such. You're also not changing the value of the variable you call it on - you need to assign the return value to [another] variable:

$(function() {
    $('#zahlungsart_0').click(function() {
            var gesamtsumme_neu = Number($('#gesamtsumme').attr('rel'))+6;
            var newVal = gesamtsumme_neu.toString().replace('.',',')
            console.log(newVal );
            $('#gesamtsumme').text(newVal);
    });

OTHER TIPS

$(function() {
    $('#zahlungsart_0').click(function() {
            var gesamtsumme_neu = Number($('#gesamtsumme').attr('rel'))+6;
            gesamtsumme_neu = gesamtsumme_neu.toString();
            gesamtsumme_neu = gesamtsumme_neu.replace('.',',');
            console.log(gesamtsumme_neu);
            $('#gesamtsumme').text(gesamtsumme_neu);
    });

Assign the values of toString(), replace() Also toString is a function

You have to call toString and reassign it to the variable; just like you have to do with replace. Like this:

$(function() {
$('#zahlungsart_0').click(function() {
        var gesamtsumme_neu = Number($('#gesamtsumme').attr('rel'))+6;
        gesamtsumme_neu = gesamtsumme_neu.toString();
        gesamtsumme_neu = gesamtsumme_neu.replace('.',',');
        console.log(gesamtsumme_neu);
        $('#gesamtsumme').text(gesamtsumme_neu);
});

The two function don't change the variable you are calling them on but return a new variable.

toString() returns a string, so try this:

var q = gesamtsumme_neu.toString();
q = q.replace('.',',');
console.log(q);
// etc
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top