1
culex
Language define in javascript confirm ?
  • 2010/1/10 22:36

  • culex

  • Module Developer

  • Posts: 711

  • Since: 2004/9/23


I am pulling my hair from this so I hope someone can save whats left of it (my hair that is)

I am trying to use language constant in a jquery / javascript confirm box, but however I try defining it, the confirm box shows eigher empty or with the raw php code inside.

Example.

<?php

// from language file

define ("_AM_INDEXSCAN_DELETESURE""Are you sure ?");

// from admin.php

<?php
<span class='delete'><a href='index.php?op=delete&name=$ff'><img src='delete.png'></img></a></span>

// Confirm javascript for delete file
echo "<script type='text/javascript'>
    $(function() {
        $('.delete').click(function() {
// var text = '<Php echo _AM_INDEXSCAN_DELETESURE; ?>'
// return confirm(text);

return confirm(<?php echo _AM_INDEXSCAN_CLEAN;?>);
        });
    });
</script>"
;



2
xsell
Re: Language define in javascript confirm ?
  • 2010/1/10 22:56

  • xsell

  • Quite a regular

  • Posts: 245

  • Since: 2008/9/2 1


do you have to echo it , can not u use html ?. see an example i use .below .beside in your Code . u wrote <?php as <php . in
<Php echo _AM_INDEXSCAN_DELETESURE;
and any way why do u use the tags <? and ?> when u already echo your Code .
return confirm(<?php echo _AM_INDEXSCAN_CLEAN;?>);


keep it html javescript easy to use for me this is my example for confirmation click .

<script type="text/javascript">
<!--
  function 
confirmation3() {
    var 
answer confirm("<? echo ""._MI_TOOLS_JAVAALERT3.""; ?>")
    if (
answer){

        
window.location "do_approve_com.php?action=statusr";
    }
    else{
        
alert("<? echo ""._MI_TOOLS_JAVAALERT_CANCEL.""; ?>")
    }
}
//-->
  
</script>
<!--
/// JAVASCRIPT ALERT END HERE
 //-->

3
Dylian
Re: Language define in javascript confirm ?
  • 2010/1/10 23:29

  • Dylian

  • Friend of XOOPS

  • Posts: 237

  • Since: 2007/7/21


Replace:
return confirm(<?php echo _AM_INDEXSCAN_CLEAN;?>);

With:
return confirm("._AM_INDEXSCAN_CLEAN.");


You can just call constants like you do with variables...
(But i gues you know that but just looked over it )

Greets Dylian.

4
culex
Re: Language define in javascript confirm ?
  • 2010/1/11 0:21

  • culex

  • Module Developer

  • Posts: 711

  • Since: 2004/9/23


Hey there and thanks both of you for the help.

I think I made the question a little more difficult than nessesary by posting an explanation of the problem rather than the full code, and furthermore make errors in this..

@Dylian yes I was aware, even though I am not very strong in javascript, and the echoing of the define outside the javascript works perfect, but when inside both my take on it, yours and xsells all fail.

I'm pretty sure this is something simple only I seem to be blind to see where it fails.

I'll post the original code here :)

<?php
// Language define in languages/english/admin.php

define ("_AM_INDEXSCAN_CLEAN""Are you sure you want to delete this file ?");
?>


<?php
// In indexscan/admin/admin.php

echo "<div class='indexscan_suspecious'>".$ff."<span class='indexscan_notxoopsinstall'>"._AM_INDEXSCAN_NOTINXOOPSINSTALL."</span><span class='delete'><a href='index.php?op=delete&name=$ff'><img src='delete.png'></img></a></span></div>";


// function to show confirm
echo "<script type='text/javascript'>
    $(function() {
        $('.delete').click(function() {
            return confirm(<?php echo _AM_INDEXSCAN_CLEAN;?>);
        });
    });
</script>"
;

?>


The code is not ready to go yet I was only testing the link, message etc etc

5
Dylian
Re: Language define in javascript confirm ?
  • 2010/1/11 0:47

  • Dylian

  • Friend of XOOPS

  • Posts: 237

  • Since: 2007/7/21


Try this line:
return confirm('"._AM_INDEXSCAN_CLEAN."');

That should work, forgot the ' to pass data to the function... (FireBug comes in handy for this kind of problems )

I also noticed that the page your generating isn't xhtml compliant so here's the compliant version (if you want it ):
<?php 
// In indexscan/admin/admin.php 

echo(stripslashes("
<div class="
indexscan_suspecious">
    "
.$ff."
    <span class="
indexscan_notxoopsinstall">
        "
._AM_INDEXSCAN_NOTINXOOPSINSTALL."
    </span>
    <span class="
delete">
        <a href="
index.php?op=delete&name=".$ff.""><img src="delete.png" /></a>
    </span>
</div>
"
)); 


// function to show confirm 
echo(stripslashes("
<script type="
text/javascript"> 
    $(function() { 
        $('.delete').click(function() { 
            return confirm('"
._AM_INDEXSCAN_CLEAN."'); 
        }); 
    }); 
</script>
"
)); 

?>

[edit]
The code block removes all \ 's.
[edit2]So if you wan't to use it. (but i gues you don't wan't to) You should add the \'s yourself.[/edit2]
So here it is again in a quote block. (Hopfully the \ 's won't be removed know...)
Quote:
EDIT: Didn't work either...

[/edit]

Greets Dylian.

6
culex
Re: Language define in javascript confirm ?
  • 2010/1/11 13:15

  • culex

  • Module Developer

  • Posts: 711

  • Since: 2004/9/23


Hey there again both of you

Thanks for the tips just wanted to let you know all is working now.

Xsell's version gave me an idea to test and it turned out it works if you step out of php to html

// Confirm javascript for delete file
?>
<script type='text/javascript'>
    $(document).ready(function()
    {
    $(function() {
        $('.delete').click(function() {
             
            return confirm('<?php echo _AM_INDEXSCAN_CLEAN?>');
        });
    });
});
</script>
<?php


But thanks for helping both :)

Login

Who's Online

193 user(s) are online (114 user(s) are browsing Support Forums)


Members: 0


Guests: 193


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits