Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7184521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:13:06+00:00 2026-05-28T18:13:06+00:00

I am working with a javascript function and I just got a liitle problem.

  • 0

I am working with a javascript function and I just got a liitle problem. I want the function to replace the “enters” to “#” so I use:coment = coment.replace(/\\n/gi,"*#*"); and it works perfect when the coment do have any “enter” but when the comment does not have any “enter”, or the comment is blank, It stops working and sends an error which says:

‘NoneType’ object has no attribute ‘replace’

How can I control that if it has any “enter” it replaces, if not, does not do anything

the “coment” comes from this:

<textarea id="coment"></textarea>

Thank You!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:13:07+00:00Added an answer on May 28, 2026 at 6:13 pm

    The problem depends upon what is actual in coment. If coment has a DOM element in it, then you need to get the value from the input field so it has a string:

    coment.value = coment.value.replace(/\n/g,"*#*");
    

    If, the issue is that coment is sometimes null or undefined, I would suggest checking first to see if coment has a valid string in it:

    if (coment) {
        coment = coment.replace(/\n/g,"*#*");
    }
    

    For the null or undefined case, you could also just precondition coment like this:

    coment = coment || "";
    coment = coment.replace(/\n/g,"*#*");
    

    You may note that I changed a couple things in the replace function too. If you’re just trying to replace the newline character, you don’t need the double backslash inside a regex definition and there’s no reason for the “i” flag on the regex since you don’t have any letters in the pattern.

    To know specifically which of these applies, you would need to show us the code that gets the value into coment so we can see what it actually has in it or you need to examine coment in the debugger or console.log to see what it has in it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a javascript function, that works fine if it's anonymous but stops working
I have this function working <script type=text/javascript> $(window).scroll(function() { if ($(window).scrollTop() == $(document).height() -
Ok just got assigned to a new project and have never dealt with Javascript
I've got a Javascript mess that looks something like: Note: Not working code, just
Window.open javascript function is not working in Mozilla, but working in other browsers, here
I tried to write a function to check key code with JavaScript. It's working
can someone explain me why this script is not working? <script type=text/javascript> function destroy(ID)
Working on an AJAX website (HTML,CSS,JavaScript, AJAX, PHP, MySQL). I have multiple javascript functions
So I have been working with javascript for a website I am designing, shocker
Hello all I am working in javascript and html5.I want to ask that how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.