1

I would like to push JavaScript value into php:

var temp =  $('#field_id').val().charAt(0);

temp returns values 1-4.

var value = "<?php echo $variable[   .....    ]['id'] ;        ?>";

how to insert instead .....

8
  • 3
    PHP is processed by your server before the page load (= server side language), the result of the PHP process is sent through HTTP to your browser, where client side language belong (Javascript). If you want to communicate to PHP through Javascript you need to consider using AJAX. Tell us more about what you want to achieve here so we can point you in the right direction. Commented May 18, 2015 at 14:14
  • @vard php values are stored into array and I need to take one value by select. I need to do this on client side Commented May 18, 2015 at 14:19
  • So if I understand right, you want to build a select based on a PHP Array, then update that select using Javascript ? Commented May 18, 2015 at 14:22
  • i recommend to you learn more about application layers Commented May 18, 2015 at 14:25
  • @vard php values already stored in array. I would like to tell javascript what value take back. Commented May 18, 2015 at 14:28

1 Answer 1

2

Its impossible, the main reason is that Php is rendered server side ( so before it arrives to the client computer), while JavaScript is rendered in the browser ( so in the client PC).

Depending from your requirement, you may use an ajax request to get the info and update the dom with javascript, or use GET or POST request with the js variable required so that PHP will have it before it renders the page.

If you wold give me more information, I may probably help you, but the question is not specific enough

Sign up to request clarification or add additional context in comments.

2 Comments

My variable temp returns only values 1, 2 , 3 , 4 and I wauld like integrate these values into php code and tell script exactly what array element pick up

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.