Multilanguage JavaScript Alert - Any Solutions?

I've followed this guide (http://www.bitrepository.com/php-how-to-add-multi-language-support-to-a-website.html)  to implement multi-language on my site, but I have a few JavaScript alert boxes that display when validation fails, the problem is that they don't support PHP, does this mean there is nothing I could do now?

Any help / suggestions highly appreciated.
ChiehkaiAsked:
Who is Participating?
 
csupaCommented:
Hello,
The error message could be stored in a php variable, just like  here (exactly like in the guide you linked here):

in the lang.en.php

define('LANG_JS_ERROR1', 'Please fill all fields!');

in the lang.es.php
 
 define('LANG_JS_ERROR1', 'Please fillos allos fieldos!');

 

And in the javascript form validation just simply call the php variable like here:

if (theForm.field.value == "")
{
alert("<?php  echo LANG_JS_ERROR; ?>");
theForm.field.focus();
return (false);
}

The php is processed before the js is processed so this will work.

0
 
Adoryc666Commented:
If you have your javascript inside you php file, you can use the same approach as they do with the other html.
0
 
ChiehkaiAuthor Commented:
csupa:

Thanks for the nice suggestion. I didn the following :

if(null_file_count == upload_range){
            <?php echo $lang['upload_alert_nofile;']; ?>
            return true;
}

But when I view the source from browser, its :

if(null_file_count == upload_range){
                        return true;
}

Do you know why it doesn't process the PHP part?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
csupaCommented:
The java script is actually in the php file or in a separate file? It has to be in the php file and after the language part (where you include the language files).
0
 
ChiehkaiAuthor Commented:
Sorry, my bad, made a typo in the script.

Its working perfectly now, thanks.
0
 
csupaCommented:
yes, the one ; in plus :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.