0

would be possible to pass javascript variable to php and execute function on it and convert it back to javascript

what I want is to get the value on click of an input field and deocode and pass it back

<script type="text/javascript">
$('.my_id').click(function(){
    var lv = $('div.special_box form input').val();
    var lv = <?php base64_decode( 'here should come my javascript variable' )?>
});
</script>
3
  • Javascript runs in the browser and php on the server. So you would have to make a server request. You should search for ajax. Commented Jul 24, 2013 at 14:58
  • 3
    No. Javascript runs on the client. PHP runs on the server. You'll need to use AJAX calls. Commented Jul 24, 2013 at 14:58
  • Thank you for the feedback than I'm going to use ajax Commented Jul 24, 2013 at 14:59

1 Answer 1

4

You can't do it as you are asking above. Javascript is a client side language, php a server side language. While there are other methods, you should use AJAX to call a separate page that will simply return the value from the function.

lv = $.ajax({
    url: "some.php?lv=" + lv,
    async: false
}).responseText;
Sign up to request clarification or add additional context in comments.

2 Comments

Just for clarification, the php-file must echo out the result. this solution works fine if you only want ONE return-value.
@bestprogrammerintheworld is correct, although if you needed multiple values, you could always return a parsable string or XML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.