Handle apostrophe in input value with JavaScript
Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
-
Marius
- Posts:107
Handle apostrophe in input value with JavaScript
I have a JavaScript code that adds an input field for a user:
Code: Select all
var user = "O'Conner, John";
b.innerHTML += "<input type='hidden' value='" + user + "'>";
When its inserted it looks like this:
Code: Select all
<input type="hidden" value="O" Conner, John'>
How do I amend this so it outputs like this:
Code: Select all
<input type="hidden" value="O'Conner, John">
I need the value to show the full name with the apostrophe. How can I get this to work?
Admin
Posts:805
You can replace the character with its HTML entity.
As for ' - It can either be
’ or
‘
Code: Select all
var user = "O'Conner, John";
user = user.replace("'", "‘");
b.innerHTML += "<input type='text' value='" + user + "'>";
Similar Topics
- Hour and Minutes togheter in Javascript
JavaScript - jQuery - Ajax
First post
Dear Coursesweb I can not find out how to add the hours + minutes togheter.
<SCRIPT LANGUAGE= JavaScript >
day = new Date()
hr =...
Last post
See and use the following example:
<script>
var day = new Date();
let hr = day.getHours();
let mn = day.getMinutes();
let se =...
- Display message to every minute in Javascript
JavaScript - jQuery - Ajax
First post
Hello,
On eatch minute from the current hour I wanna have an message
I can not find out how to complete
I hope to get something like this (code...
Last post
If you only want to display a message to every minute, just use the setInterval() function. It calls a function repeatedly, over and over again, at...