1

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!

4 Answers 4

1
$(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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

toString() returns a string, so try this:

var q = gesamtsumme_neu.toString();
q = q.replace('.',',');
console.log(q);
// etc

Comments

0

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);
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.