PDA

View Full Version : Encoding problem with alert popup (please help) !



winpeace
07-18-2008, 03:00 PM
I am using turkish character my site.(ISO 8859-9) The forms characters appears correctly.But alert popups character set not appears correctly.

It is a english form and I transtlate words like this to turkish;



DEFINE( "ADSMANAGER_FORM_AD_TEXT", "Açıklama");
DEFINE( "ADSMANAGER_FORM_KINDOF", "Gönderi Şekli");


and the codes...

<script type="text/javascript"><!--//--><![CDATA[//><!--
function submitbutton(mfrm) {
var me = mfrm.elements;
var r = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]", "i");
var r_num = new RegExp("[^0-9\.,]", "i");
var r_email = new RegExp("^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,3}$" ,"i");

var errorMSG = '';
var iserror=0;

<?php
if (function_exists("loadEditFormCheck")){
loadEditFormCheck($row);
}
?>

if (mfrm.username && (r.exec(mfrm.username.value) || mfrm.username.value.length < 3)) {
errorMSG += mfrm.username.getAttribute('mosLabel').replace('&nbsp;',' ') + ' : <?php echo addslashes(html_entity_decode(sprintf( ADSMANAGER_VALID_AZ09, ADSMANAGER_PROMPT_UNAME, 4 ),ENT_QUOTES)); ?>\n';
mfrm.username.style.background = "red";
iserror=1;
}
if (mfrm.password && r.exec(mfrm.password.value)) {
errorMSG += mfrm.password.getAttribute('mosLabel').replace('&nbsp;',' ') + ' : <?php echo addslashes(html_entity_decode(sprintf( ADSMANAGER_VALID_AZ09, ADSMANAGER_REGISTER_PASS, 6 ),ENT_QUOTES)); ?>\n';
mfrm.password.style.background = "red";
iserror=1;
}

if (mfrm.email && !r_email.exec(mfrm.email.value) && mfrm.email.getAttribute('mosReq')) {
errorMSG += mfrm.email.getAttribute('mosLabel').replace('&nbsp;',' ') + ' : <?php echo html_entity_decode(addslashes(ADSMANAGER_REGWARN_MAIL),ENT_QUOTES); ?>\n';
mfrm.email.style.background = "red";
iserror=1;
}

// loop through all input elements in form
for (var i=0; i < me.length; i++) {

if ((me[i].getAttribute('test') == 'number' ) && (r_num.exec(me[i].value))) {
errorMSG += me[i].getAttribute('mosLabel').replace('&nbsp;',' ') + ' : <?php echo html_entity_decode(addslashes(ADSMANAGER_REGWARN_NUMBER),ENT_QUOTES); ?>\n';
iserror=1;
}

// check if element is mandatory; here mosReq="1"
if (me[i].getAttribute('mosReq') == 1) {
if (me[i].type == 'radio' || me[i].type == 'checkbox') {
var rOptions = me[me[i].getAttribute('name')];
var rChecked = 0;
if(rOptions.length > 1) {
for (var r=0; r < rOptions.length; r++) {
if (rOptions[r].checked) {
rChecked=1;
}
}
} else {
if (me[i].checked) {
rChecked=1;
}
}
if(rChecked==0) {
// add up all error messages
errorMSG += me[i].getAttribute('mosLabel').replace('&nbsp;',' ') + ' : <?php echo html_entity_decode(addslashes(ADSMANAGER_REGWARN_ERROR),ENT_QUOTES); ?>\n';
// notify user by changing background color, in this case to red
me[i].style.background = "red";
iserror=1;
}
}
if (me[i].value == '') {
// add up all error messages
errorMSG += me[i].getAttribute('mosLabel').replace('&nbsp;',' ') + ' : <?php echo html_entity_decode(addslashes(ADSMANAGER_REGWARN_ERROR),ENT_QUOTES); ?>\n';
// notify user by changing background color, in this case to red
me[i].style.background = "red";
iserror=1;
}
}
}

if(iserror==1) {
alert(errorMSG);
return false;
} else {
return true;
}
}
//--><!]]></script>

and problem picture
http://img183.imageshack.us/img183/3817/eaje7.gif

jscheuer1
07-18-2008, 03:32 PM
Alerts will not use HTML named or numbered entities like:


&copy;

or:


Ş

You need to find the hex value of the character and use it like so (for the copyright symbol which is hex a9):


\xa9

Example in an alert:


alert('\xa9');

You can also use four digit Unicode character codes, once again for copyright:


alert('\u00a9');

or for that other symbol (Ş):


alert('\u015e');

winpeace
07-18-2008, 03:43 PM
Sorry but I don't understand
What am I write in language file
for example here
DEFINE( "ADSMANAGER_FORM_AD_TEXT", "A&ccedil;ıklama");

jscheuer1
07-18-2008, 03:52 PM
You are going to need some Unicode character charts, there are several online, use Google to find them. For that particular character, it would be:


DEFINE( "ADSMANAGER_FORM_AD_TEXT", "A\u00e7ıklama");

If this is used in HTML as well as in alert though, there could be problems. You may have to separate the text used in alerts from that used in the markup if your code isn't already setup that way.

winpeace
07-18-2008, 04:05 PM
not solved problem

http://img380.imageshack.us/img380/3025/asdby0.gif

language and php files in attachment.Please help.
Sorry my bad english

jscheuer1
07-18-2008, 04:13 PM
This works here:


<script type="text/javascript">
alert('A\u00e7iklama');
</script>

I'll have to have a look at your code in more detail, as it apparently is messing this up. You might be able to just double the escape though:


DEFINE( "ADSMANAGER_FORM_AD_TEXT", "A\\u00e7ıklama");

jscheuer1
07-18-2008, 04:16 PM
DEFINE() is not a function. I need to see your page:

Please post a link to the page on your site that contains the problematic code so we can check it out.

winpeace
07-18-2008, 04:22 PM
****-**

jscheuer1
07-18-2008, 05:46 PM
Sorry, I didn't see your attached files. That's PHP (not something I'm real good at), not javascript.

What I told you about the alert in javascript is accurate. A javascript alert will not accept HTML entities. You must use hex or Unicode character escapes (as I've already explained) for any unusual characters in the alert.

If you need help arranging your server side code go to the PHP forum:

http://www.dynamicdrive.com/forums/forumdisplay.php?f=11

mas3147
04-18-2012, 10:55 PM
I am using turkish character my site.(ISO 8859-9)
and problem picture
http://img183.imageshack.us/img183/3817/eaje7.gif

I solve this problem with just opening script file in notepad and save again in unicode format, it works for me:)