Assigning javascript variable to php variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Totenkopf
Forum Newbie
Posts: 2
Joined: Mon May 01, 2006 10:30 am

Assigning javascript variable to php variable

Post 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.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
Totenkopf
Forum Newbie
Posts: 2
Joined: Mon May 01, 2006 10:30 am

Post 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
Post Reply