4

I want store clickede_id value into $id2[] give me some suggestions and also suggest some advance details

function yes(clicked_id)
    {

        var it1=clicked_id;

        alert(it1);

        var tt1=1;


        var tt2= "<?php echo($id2[var it1]); ?>";


        //var tt2=document.getElementById("idcheck").value;
        alert(tt2);
        var tt3=document.getElementById("idcheck1").value;
        //alert(tt3);

    }
Alex
  • 21,273
  • 10
  • 61
  • 73

2 Answers2

0

When you develop a web application, you are creating tools to let client and server communicates (over the HTTP protocol). This communication is based on Requests and Responses.

The client send request to server and the server responds with a reponse. In your case, you choosed PHP as the server-side language that will create your responses as answers to client request. Thes responses are HTML (+ javascript). Anyways, the reponses are static stuff to be interpredted by the client.

So the code you have sent is seen by the browser as:

function yes(clicked_id)
    {

        var it1=clicked_id;

        alert(it1);

        var tt1=1;


        var tt2= 3; // or whatever value returned by php

        var tt2=document.getElementById("idcheck").value;



        var tt3=document.getElementById("idcheck1").value;
        // ajax call here

    }

When you say : store data from javascript to php (even if it doesnt look as a correct senetence), you mean sending data from client to server. It can be done via a classical Post request (via form submit with page refresh) or via ajax without page refresh.

For ajax, please to check jQuery documentation for $.ajax function (if you want to have a cross browser compatible solution), or XMLHTTPRequest object if you want raw javascript and do the cross-browser compatibility yourself.

Adib Aroui
  • 4,981
  • 5
  • 42
  • 94
0

PHP executes in the server and send the result to your browser to display. Your JS executes at this browser stage. What you need to understand is that PHP has already been finished it's execution when your JS gets a chance to execute. Trying to change something in PHP through the JS is trying to access the past.

But, the good news is, that you can adopt a model where you feed your JS through the PHP script (look at this echo "<script>var s = 'from php'</script>") and JS feeds your NEXT php execution. You can use ajax or direct page calling for this.

Probably you should read this question: How to pass data from Javascript to PHP and vice versa?

Community
  • 1
  • 1
Charlie
  • 22,886
  • 11
  • 59
  • 90
  • i want to execute with in the function if that possible and give some example for that code to access ajax – ibrahim.k Ibrahim Jan 09 '16 at 09:07
  • 1
    An example is a whole model. Please read the question I have linked. That will be a good starter. Please understand that you can't do a copy-paste job with a whole new concept. You need to learn it and use it in your project. – Charlie Jan 09 '16 at 09:10