1

I FIX THAT WITH

confirmReset(\''.$nodetitle.', '.$nodeid.'\')

Question :

I want to run a simple JavaScript function on a if user press the button, alert confirm show the ID and TITLE of page and Finaly redirect the custom url my problem is just ID have passed and Title not!

Variables

$nodetitle = "Title one";
$nodeid = 150;

HTML

<button class="btn" onclick="return confirmReset('.$nodetitle.', '.$nodeid.');">

JAVASCRIPT

function confirmReset(nodetitle, nodeid) {
 var r = confirm('Node with ( ' + nodeid + nodetitle + ' ) Delete?');
 var url = window.location.pathname;
 var pathArray = url.split( '/' );
 var host = pathArray[1];

 if (r == true) {
    document.location.href = 'node/'  + nodeid + '/delete';
 } else {
   // alert('it didnt work');
 }
 return false;
}

this code just return numbers like Nodeid and nodetitle NOT returned

Thanks for you help my friends...

4

1 回答 1

0

PHP

<?php
$nodetitle = "Title one";
$nodeid = 150;
?>

HTML

<button class="btn" onclick="return confirmReset('
<?php echo $nodetitle;?>', '
<?php echo $nodeid;?>');">
    Hello World
</button>

Javascript

<script type="text/javascript">
    function confirmReset(nodetitle, nodeid) {
        var r = confirm('Node with ( ' + nodeid +', '+ nodetitle + ' ) Delete?');
        var url = window.location.pathname;
        var pathArray = url.split( '/' );
        var host = pathArray[1];
        if (r == true) {
            document.location.href = 'node/'  + nodeid + '/delete';
        }
        else {
            // alert('it didnt work');
        }
        return false;
    }
</script>
于 2018-01-21T13:36:55.893 回答