Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm using JavaScript to redirect a page with dynamic parameter.

Here is the code, I had to use the PHP function inside JavaScript. It works but it isn't using the javascipt variable

<script type="text/javascript">
var $map = jQuery.noConflict();
       $map(document).ready(function(){
            $map("#map_search").click(function(){
                  var staffname = $map("#staffname").val();//alert(staffname);

                  var from = $map("#cdate_from").val();
                  var to = "<?php echo site_Encryption(from); ?>";alert(to);
                  var status = $map("#status").val();
                  window.location = "http://localhost/staff/booking.php?date="+to+"&tdate="+to;


var to = "<?php echo site_Encryption(from); ?>";alert(to);

Here I use the PHP function and "from" is JavaScript variable that I want to use.

share|improve this question
2  
u cant do it...u can either submit the variable via form or via ajax –  Vicky Gonsalves Nov 6 '13 at 14:03
5  
never forget that php is executed on the server side, and that javascript is executed on the client side. What you want to do is impossible. –  Brice Nov 6 '13 at 14:04
    
What is site_Encryption() there –  Pavan Kumar Nov 6 '13 at 14:09
    
site_Encryption() is php function for encrypt code –  chetan Nov 7 '13 at 6:43

1 Answer 1

up vote 2 down vote accepted

You can do an ajax request, something like:

var from = blablah...;
$.getJSON("encryption.php", {from : from}, function (data)
{
alert(data.to);
});

encryption.php :

<?php
blabla...
echo json_encode(array("to" => site_Encryption($_GET["from"])));
?>

(It's a sample code, don't copy-paste, read some ajax tutorials ^^)

An alternative could be to make the encryption on client side.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.