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: 106
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
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
-
Adding content from a Div into an input text field
JavaScript - jQuery - Ajax
First post
I still don`t understand how I can get the results from a div into a text input form field ?
<div id= div2 > Content </div>
I...
Last post
Thanks Chief for all your support....
My URL-extractor is working
in the comment-system
-
Converting a salary input string to number
JavaScript - jQuery - Ajax
First post
I have the following problem:
1. eliminate thousand separators(,) 5,555 to 5555.
2. if the user inputs 55,66 replace , with . and get the value...
Last post
Try the function from the following code:
function salNr(s){
//If there is comma before the last two digit, replace it with dot, else remove...
-
Get id from url in javascript
JavaScript - jQuery - Ajax
First post
Last time you learnt me how to add an id from url to a javascript
but by this script it is not working what do I do wrong ????
<?php...
Last post
Maybe there is some mistake in other part of your script.
Check to see if there is any js error in browser console, F12.
What value it shows in...
-
Problem with value of $_GET from php to javascript
PHP - MySQL
First post
I found a script from: tutorialzine.com/2014/09/cute-file-browser-jquery-ajax-php
what I wanna use for my website.
But I can`t find out how to...
Last post
Thanks Chief for the support `it is working now`
-
Get country code from JavaScript to PHP
PHP - MySQL
First post
Chief I have a problem to get the countrycode into my sql-statement.
Please help me out....
This script is to detect the countrycode...
Last post
The JavaScript code cannot be executed in php.
Javascript is executed in browser, after the php finished to output its data.
Also, Javascript it is...