I am working with jquery tag input but when I create some tag, the tag automatically include some random character.
Below is the screenshot of the tag input box
Link of image
I don't know how to get rid of it.. I searched on google they give me solution to add some meta tag and I also added some meta like this
<meta charset="UTF-8">
this is the plugin Link which i am using
this is the html code
<input id="expert_tags" name="spl_tags" type="text" class="form-control tags" value=""/>
this is javascript code
$('#expert_tags').tagsInput({});
thats it only that much of code for tag input
Maybe use the following meta tag:
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
If you are getting the tags via ajax you should check if the header is set on the server side. In PHP it would look something like this:
header('Content-Type: text/html; charset=utf-8');
Related
I'm looking for a Javascript equivalent of a technique I've been using in PHP. That is, to place even the most basic page setup:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
...in a php file like 'doc_start.php' and then start every page in my site with...
<?php require_once('/path/to/doc_start.php); ?>
Now I need to begin a project that's strictly HTML and JS (no PHP) and want a similar way to avoid duplicating basic, common HTML elements. Obviously, I want to do more than this very basic stuff, like import JQuery in every page, link to a common stylesheet, etc. Again, all easy in PHP, but I'm still kind of a newbie in JS.
I've read about HTML5 includes, but can't seem to find anything that addresses what I want to do
In order to import other pages into your current document, you need to use a link tag.
For example....
<head>
<link rel="import" href="/path/to/imports/stuff.html">
</head>
This will allow you to reference other html, css or javascript documents into your page without copying and pasting the same code within each page.
https://www.w3schools.com/html/html_links.asp
Javascript and PHP are different languages for very different purposes. But assuming you have some element you don't want to repeat some elements one solution is the following:
Save the HTML elements that you don't want to keep repeating as a string. Then use the .innerHTML property to add elements.
The .innerHTML property stores the mark up of an element as a string.
For example, if we have the following <div>:
<div class="example"> <br> Hello there this is a test! </div>
...and we use .innerHTML:
console.log(document.querySelector(".example").innerHTML);
It will output "<br> Hello there this is a test!".
We can add to the .innerHTML using the += operator. So if you want to add something inside the body it's as simple as:
var something = "some HTML";
document.body.innerHTML += something;
Hope this was what you were looking for!
I am making a simple website which changes the image displayed when a button is clicked. But my code doesn't seem to be working as when I click on the button 'Click!' the alt text gets displayed instead of the image changing.The source of the images is perfectly fine, as when I use the same source outside the script the images show up.
<head>
<title>Pic Change</title>
<meta charset="utf-8">
<meta name="Pic Change">
<meta name="keywords" content="face,PES">
<meta name="author" content="Thalle">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
</head>
<body class="body" style="background-color:#4682B4">
<script>
function display(whichimage){
if(whichimage == 0){
document.getElementById('Click').src="C:\.....\Memes\Animals\initial.jpeg"
}
else{
document.getElementById('Click').src="C:\.....\Memes\Animals\Whenlife.jpeg"
}
}
</script>
<image id="Click" src="C:\......\Memes\Animals\initial.jpg" alt="Click Button to click picture" style="width:300px;height:300px" >
<p>
<button type="button" onclick="display(1)">Click!</button>
<button type="button" onclick="display(0)">Reset</button>
</p>
</body>
</html>
The code is fine, you just forgot the file:// before the start. This code shows that when you give a working image src in your code, it will work just fine. Also, don't use files from your disk on Stack Overflow, it gives out private information that you probably don't want on the web.
<head>
<title>Pic Change</title>
<meta charset="utf-8">
<meta name="Pic Change">
<meta name="keywords" content="face,PES">
<meta name="author" content="Thalle">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
</head>
<body class="body" style="background-color:#4682B4">
<script>
function display(whichimage){
if(whichimage == 0){
document.getElementById('Click').src="http://www.iconarchive.com/download/i86425/martin-berube/flat-animal/duck.ico"
}
else{
document.getElementById('Click').src="https://maxcdn.icons8.com/Share/icon/Animals//duck1600.png"
}
}
</script>
<image id="Click" src="http://www.iconarchive.com/download/i86425/martin-berube/flat-animal/duck.ico" alt="Click Button to click picture" style="width:300px;height:300px" >
<p>
<button type="button" onclick="display(1)">Click!</button>
<button type="button" onclick="display(0)">Reset</button>
</p>
</body>
</html>
You forgot the protocol (file://). It should be like
document.getElementById('Click').src="file://C:\Users...";
otherwise it will be just appended to the src everytime you click a button.
Try to put your JavaScript in the <head> section. Then it might work.
Also. There is no such thing as image in HTML. It's img.
In javascript, you need to escape backslashes in strings, so in adresses in particular. Replace all "\" by "\\".
You shouldn't load images from your disk. We and others can't see it. If you use relative paths and you make sure every images and the HTML file is in the same directory, that should be fine. Even if you do, you must specify the file:// protocol. But if you use external images from a website, we could see them.
There is no <image> element in HTML. It's just <img>.
You should type \\ instead of \, because the \ character has a special meaning. However, Javascript is smart, and you can use / too, don't have to follow Windows' method.
Please don't use the onclick attribute. It's really old. Instead use event listeners.
Right now I don't know what is the problem in your code extacly, however, there is a working example:
<!DOCTYPE html>
<html>
<title>Pic Change</title>
<script>
document.addEventListener("DOMContentLoaded", function() {
document.querySelector("button").addEventListener("click", function() {
document.querySelector("img").setAttribute("src", "file://C:/Data/300x300-colored.png");
});
});
</script>
<p><img src="file://C:/Data/300x300.png" /></p>
<p><button type="button">Click!</button></p>
</html>
If both images and the index.html is in the C:\Data directory, it works fine.
For some reason this character is getting generated in my HTML email when it is being sent: –. I have tried replacing it with nothing in my PHP using preg_replace('/–/', '', $var), but that is not working. For some reason when I get an email containing HTML this character shows up. I am guessing it is generated from this JavaScript in my code somehow:
$('.comments0').click(function(){
$('.comments').val($('.comments').val() + 'Our warranties are:\nNew – 1 year\nRemanufactured - 6 months\nRepair - 6 months');
});
If it is not being generated with JavaScript, I am not sure how this character keeps getting created in the middle of my HTML. It gets generated right after New, just like this: New – 1 Year. I have no idea why this character is coming up randomly like this.
By the way, here is the HTML directly related to that JavaScript:
<form action="?AddToQuote" method="POST" id="myForm" name="myForm">
<input type="checkbox" name="comments[0]" class="comments0" id="comments0" /><label>6 Months Warranty</label>
<textarea cols="75" rows="6" name="comments" class="comments" id="comments"><?php if(isset($_SESSION['comments'])) { echo $_SESSION['comments']; } ?></textarea>
</form>
Apparently the characters in your message were copied/pasted from somewhere else. If you delete them and manually retype directly in the JS source that should do the trick.
This is an en dash:
New – 1 year
If you don’t serve the script with the same encoding as it was written in, there will be errors. So make sure it’s saved as UTF-8 and serve it as UTF-8. If the JavaScript is part of your HTML, add this at the top of the <head> (HTML5):
<meta charset="utf-8">
You can test it:
$ echo '–' > test.html
$ firefox test.html
(– shows up in a browser)
Be sure that your text editor / IDE is set to save files as UTF-8 with NO BOM.
Also, be sure you are using <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> in your page <head> and setting your emails up as UTF-8.
I have the following javascript, loading my menu on all of my pages
<script type = "text/javascript">
$(document).ready(function () {
$("#menudiv").load("menu.html");
});
</script>
I havent included the menu as it is a completely standard list, formatted to look like it does. One of the menu option contains the character "å", how can I make my page display this character correctly?
This usually happens when the server doesn't set the encoding of menu.html correctly. Make sure the correct encoding is in the headers. (see this document) Especially, make sure that the Content-Type header is correct and that you have a <meta charset="..."> element in menu.html
The encoding of the existing page doesn't matter at all! Whenever you download something, the browser will look for the encoding of the new data, convert that to Unicode and only then, merge the new data with what it already has.
add this HTML Meta tag in your page:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Or in HTML5 Way :
<meta charset="iso-8859-1">
Add the following meta tag to the head of your HTML document:
<meta charset="iso-8859-1">
Use the HTML entity code for displaying this and other ISO characters:
å or å
More information on HTML entities from w3: http://www.w3schools.com/tags/ref_entities.asp
I'm using with the file: jquery.fileuploader.min. when I change the string in the file from English text to Hebrew it returns wrong encoding.
I changed to:
text:{uploadButton:"עיין",cancelButton:"Cancel",......
instead of:
text:{uploadButton:"Upload A File",cancelButton:"Cancel",......
Then I get in the Html button: "����" instead of "עיין".
I have in the body a meta tag of Enciding:
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
So I don't know why it happens.
Like adeneo wrote, I opened the jquery.fileuploader.min sheet in Notepad and saved it to utf-8 unicode instead of ansi