etymole Posted October 21, 2010 Share Posted October 21, 2010 Hi. Sorry if I'm posting in the wrong forum. My problem spans all three types. I'm working as an intern at a web development company and am trying to create a select box to contribute to filtering a table by country based on the country selected, but without submitting, so I guess I need a bit of javascript to do this. I have a <select> drop down menu that is pulling information from a spreadsheet (created by the company). I have that working, but now what I want to do is pull the value of the currently selected item (country) out and place it in a variable so that I can run a compare with all of the current 'user' countries that match the selected country. I apologise if I sound a little confusing. It's really a simple thing I'm trying to do but because I want to do it in real-time I don't want to use a submit and a $Get to get the value passed. I then want to compare the value obtained with an already existing PHP variable(s). I'm afraid I don't have the code as I couldn't take it home. It looks something like this: I've used open and closing <?php ?> tags because it makes it easier for me to read instead of using quotation marks and echo's all over the place, sorry if this is bad practice, I hope it's readable. $countries = array(country pulling method) blah blah... <select id="countries"> foreach($countries as $value) { <option value="<?php $value ?>" > <?php $value ?></option> } </select> Now, to re-iterate, this select box displays all of the countries in the spreadsheet on each line as I want. Can anyone help me get the real-time selected country without the need for a Submit? Appreciate any help Thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 22, 2010 Share Posted October 22, 2010 You want to use AJAX. There are countless tutorials available and I couldn't explain it adequately in a forum to do it justice. Basically, you will use JS to trigger when a chnage is made to the select list and then "submit" that value using JS to a PHP page. That PHP page can then use the value(s) to run a query, or whatever you want to do, then return results back to the JS calling function. The JS can then do something such as update a table of records based on the currently selected country. All of this happens in real time without having to submit/refresh the page. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.