How to prevent newline character in textarea I'm building a form in a module for Drupal 7 and I want to add a textarea as I would like it to be multiline so that text overflows on the next line, etc. but I don't want users to be able to create a new line if that makes sense. How can I achieve this? 

Also, I would like to add a "Select All" button for the textarea and I have followed this article but it doesn't seem to have worked.

I know have the first part of my question solved, but still can't get the "Select All" button working. I have confirmed that the Javascript function does run by adding console.log, but it doesn't do the job. All that happens is the page reloads and no text is selected in the text area.
If using jQuery is an option for you, you can do something like this:

$('#yourTextAreaID').keyup( function() {
  $(this).val( $(this).val().replace( /\r?\n/gi, '' ) );
});


This code will replace the newline character on the fly, after the user types it. This code can be added in a custom.js file of your theme that you include in every page of your site, or you can alternatively use a hook_form_FORM_ID_alter in your custom module in conjunction with the drupal_add_js function to add the specific js file only in the specific form's edit page.

Keep in mind that if Javascript is disabled in the user's browser, he will be able to insert newline characters. In order to prevent this, you will have to add a custom validation function in your form. A very good tutorial on how to do this can be found here. The most important parts are:

1) Use a hook_form_FORM_ID_alter (in the tutorial he uses the old-school approach with hook_form_alter).  

2) Add an extra validation function with something like:

array_unshift($form['#validate'], 'MYMODULE_form_validate');


3) Write your custom validation function (name it: MYMODULE_form_validate) that checks for \r?\n in the value of the textarea in the $form_state variable and return a descriptive error if there is a newline character.

Regarding the second part of your question, you should add some more information about what exactly didn't work. Did you clear the cache after following the steps? Do you get any errors in the log messages? Did you add console.log in your Javascript to verify that is being executed?