How to avoid escape character while retrieving from textbox/textarea through jquery? - javascript

here i'm copying the contents from webpage and pasting the contents in form fields like textarea. while retrieving the form contents, escape characters are also coming along which is breaking the functionality. how to avoid the escape characters and retrieve only the given text. The escape characters are not visible in the form fields, but its visible in json.
the above 1st image is entered text and second image is retrived in json. Help me out in this
Thanks.

Try to remove the line breaks with this line of code:
text = text.replace(/(\n|\r)/gm,"");
Cf: How to remove all line breaks from a string?

Related

Get textarea with line-breaks in jQuery

I have to somehow split text from textarea by rows. It's not a problem when user hit enter on it because then in string is \n char so it's easy to detect.
But what if browser automatically move some word to another row in textarea? Is browser put some special char when sentence is split automatically?
var splitted = $('#textArea').val().split("\n");
Is not a soulution because it's work only when user hit enter.

How to remove one or more white space before a text in the input field

I have validated input fields to check for empty fields. Later I noticed someone can just enter white space and submit the form. Can someone help me remove white space before text but accept space in the middle of the text of the input. I tried using this but will not allow white space in the middle of the input
$('input').keyup(function() {
$(this).val($(this).val().replace(/\s+/g, ''));
});
How do I fix this?
First of all, nothing to do with your question, but you should be validating the field only when the user is trying to submit your form, so, you should use the HTMLFormElement's submit event.
Second, you should be revalidating your form in your backend, because people can just change things client side, via console/debug etc, and that's a really security matter.
Third, about your question itself: You can use the String.prototype.trim method, as follows:
$('input').keyup(function() {
$(this).val($(this).val().trim());
});
.trim() removes leading and trailing spaces leaving ones in the middle unmolested.
You need trim method. Short example:
var str = " Hello World! ";
alert(str.trim());
The alert will display Hello World without white spaces.
More information here:
http://www.w3schools.com/jsref/jsref_trim_string.asp
you can use String trim() Method
Reference is here

Oracle APEX comma alternatives in Text Field

Im working with Oracle Application Express (APEX). I have a page with a link and a page with a Text Field (in simple terms). When i click on that link, a JavaScript function puts a coordinate to the second page with the Text Field. The coordinates should appear in that Text Field. The point is: They really appear, but only a part of them. I can show you that:
This should appear in the Text Field:
LatLng(48.30247, 16.02837)
But the Text Field shows only this:
LatLng(48.30247
I realised the problem: Apex thinks, that it should stop writing something in a Text Field, when there is a "," (comma). But I need that "," for my Database. So my question: Is there another way to write the comma? Or can I tell Apex to not do anything when a comma appears?
Parameters in an Apex URI are colon separated, but multi-value parameters, such as lists of page items to set, are comma separated. Apex thinks you are trying to set the value of P202_TEXT_FIELD to "LatLng(48.30247" and the value of a second, unspecified page item to ", 16.02837)".
You can escape commas in an Apex URI by enclosing the value in backslashes, ie:
"\"+popup_coord+"\"

Escape My HTML Character

I have a requirement where if user enters anything in the free text field, it should be written on Page, problem i am facing when user enters any html character, it doesnt write anything, as it takes it as html character instead of normal text.
http://jsfiddle.net/mJwwS/
$('#add').on('click',function(){
$('#hey').html($('#oye').val());
});
Use .text() method instead:
$('#hey').text($('#oye').val());
DEMO: http://jsfiddle.net/mJwwS/1/

How do I bind a non-breakspace(alt-288 or  ) upon pressing the space bar in javascript?

I'm using OpenMRS, it's an opensource medical records system. OpenMRS has a built-in html editor and I use this mostly in javascripting ang building the forms. In one of my forms,I have a textarea. My client would like his entries(in paragraph or in list) to be indented in the textarea.
Now when you try indenting the paragraph in the textarea then save the changes and preview the form, the paragraph becomes justified instead of retaining the indented lines.
However, if I try indenting the paragraph using ascii code for non-break space by typing   or pressing alt-288, the paragraph becomes indented thus giving me the desired result. Now, the users don't prefer typing or pressing ascii equivalents coz that'll be hassle on their part.
I'm using mostly javascript and jQuery because it's what openmrs supports. If I could somehow bind the non-break space character upon pressing a key then this will work, but I'm at a lost here. How will I do this in javascript or jquery?
One solution which might work for you is to replace leading spaces in the textarea when you process/save or even each time it changes it something like :
ta.value = ta.value.replace (/\n +/, function (m) {
return '\n' + Array (m.length).join ('&#160');
});
The Array ... constructs creates an array containing length elements then joins with your non-breakspace character effectively creating a string of that many space chars.
Another possibility is to watch for space characters entering the text-area and transforming them. See here : Can I conditionally change the character entered into an input on keypress?

Categories