Page 1 of 1

Assigning javascript variable to php variable

Posted: Mon May 01, 2006 10:37 am
by Totenkopf
I have a js function 'func' that when called, I like the input variable 'choice' to be
assigned to a php variable' $choice' (to be used later in a sql query),
but I am not sure how to go about doing this.

Code:

Code: Select all

echo "
  <script TYPE=\"text/javascript\">
    
    function func(choice){		
";		

//	$choice = choice;     INCORRECT !!! 

echo "
    }		
    </script>
";

Thanks for all the help you can give me.

Burrito: Use PHP tags when posting code in the forum.

Posted: Mon May 01, 2006 11:08 am
by Burrito
you will have to send the info back to the server in order to set a php var.

you could do it with ajax, but the 'standard' way is to send it back via post or get.

Posted: Mon May 01, 2006 12:32 pm
by Totenkopf
How do I populate the options in my select statement with the reponse text
from the server? The server is only returning echos of
<option>opt1</option><option>opt1</option> etc...

Code: Select all

<script TYPE="text/javascript">

.
.
.

function updateSub() {

	if (xmlHttp.readyState == 4) {
		var response = xmlHttp.responseText;
		document.getElementById("sub")._???_ = response;
	}
}

.
.
.

</script>

.
.
.


<select id="sub">

</SELECT>





Thanks