michaelk Posted January 11, 2019 Share Posted January 11, 2019 Hi, I have the following code: <input name="data" type="text" id="data" value="<?php print utf8_decode($data_attiva)?>" size="30" readonly onChange="aggiorna_data_nascosta()" style="font-size:15px; font-weight:bold"> <input type="button" id="trigger" onClick="" value="scegli data" style="background-image:url(img/icons/calendar-gray.png); background-repeat:no-repeat; background-position: 5px center; padding-left:25px"> <script type="text/javascript"> Calendar.setup({ inputField : "data", // id of the input field ifFormat : "%A %d %B %Y", // format of the input field (even if hidden, this format will be honored) daFormat : "%A %d %B %Y", button : "trigger", // ID of the span where the date is to be shown weekNumbers : "true", range : [2002, (new Date().getFullYear())+2] }); </script> And the following js function: function aggiorna_data_nascosta() { var yearCurrent = now.getYear(); var day=window.calendar.date.getDate(); var month=window.calendar.date.getMonth(); var year=window.calendar.date.getFullYear(); var listYears=document.getElementById('anno'); for (i=0; i<listYears.length; i++) { if (listYears.options[i].text == year) { document.getElementById('anno').selectedIndex=i; } } document.getElementById('giorno').selectedIndex=day-1; document.getElementById('mese').selectedIndex=month; } The problem is the following: When I open the page I see the date in the right encoding... for example "Venerdì 11 Gennaio 2019"... thanks to the PHP function "utf8_decode(data_attiva)" in the first line. Unfortunately when I click the button with id "trigger" and I change the date the new date appears in the wrong encoding... for example it becomes "Venerdì 11 Gennaio 2019". Can you suggest me a way to put the date to the right encoding when I change the date with javascript? My current PHP header of the page is: header('Content-Type: text/html; charset=iso-8859-1'); Quote Link to comment https://forums.phpfreaks.com/topic/308148-js-encoding-help-utf-8/ Share on other sites More sharing options...
requinix Posted January 11, 2019 Share Posted January 11, 2019 The problem seems to be with the Calendar thing, not your code. The best thing you could do, and what would be one way to fix your problem, would be to use UTF-8 instead of ISO 8859-1 for your pages. Quote Link to comment https://forums.phpfreaks.com/topic/308148-js-encoding-help-utf-8/#findComment-1563443 Share on other sites More sharing options...
michaelk Posted January 14, 2019 Author Share Posted January 14, 2019 On 1/11/2019 at 5:46 PM, requinix said: The problem seems to be with the Calendar thing, not your code. The best thing you could do, and what would be one way to fix your problem, would be to use UTF-8 instead of ISO 8859-1 for your pages. Yep sure but I am handling with an old app written in PHP 5 that has three different charsets (UTF-8, ASCII and ISO 8859-1). It's very complicated using UTF-8 instead of ISO 8859-1 for the pages (I have already tried it...). I was wondering if it's possible to put some utf8-decode directly in the javascript code... and where. I am not very expert about Javascript... Quote Link to comment https://forums.phpfreaks.com/topic/308148-js-encoding-help-utf-8/#findComment-1563545 Share on other sites More sharing options...
requinix Posted January 14, 2019 Share Posted January 14, 2019 4 hours ago, michaelk said: I was wondering if it's possible to put some utf8-decode directly in the javascript code... and where. I am not very expert about Javascript... You probably could but I wouldn't recommend it. This encoding this is going to hurt you over time. It'll be better if you buckle down and start fixing it now. Quote Link to comment https://forums.phpfreaks.com/topic/308148-js-encoding-help-utf-8/#findComment-1563552 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.