Jump to content

Recommended Posts

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');

 

Link to comment
https://forums.phpfreaks.com/topic/308148-js-encoding-help-utf-8/
Share on other sites

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...

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.