Converting a Jquery variable into a php variable

Hi I’m not sure whether this is a php, javascript or ajax question. Because I’m using wordpress press I think ultimately my solution needs to be php. I have a select form with an array of options, the select id is “company_size”. When an option is selected I can get the selected value with the below jquery. How would I go about turning this into a php variable? Or can I just can get the value with php? any help would be great. Cheers

var $j = jQuery.noConflict();

var size= $j("#company_size :selected").text();

It’s kind of hack-ish, but you could use AJaX to send that value to a php page that inserts the value into the session scope, making it available globally.



The answer depends on what you are doing exactly. If the user selects an option and the results are shown on a new page, the data would be submitted in a form. The form can be submitted by query using the ‘change’ event.

<form action='#' method='get' />

<select name='company size'>
<option>option 1</option>
<option>option 2</option>
<option>option 3</option>
<option>option 4</option>


If the data is shown on the same page, the process is basically the same, except you would use Ajax to submit and retrieve the form data.

You would then use wp_query to search for posts that match the variable.


A global variable would be hackish and isn’t needed. There are a couple of methods that I outlined above for sending the variable directly to a php processor.

suppose your jquery variable is var j.okay.

create a input type and asign id xyz.

now write document.getelelementbyid(‘xyz’).value= var j

thn your value will be asigned to inputtype.

hope this helps.

Thanks everyone, I’ll give this a try. Cheers