AV1611 Posted October 4, 2013 Share Posted October 4, 2013 Ok, I have NEVER tried to use AJAX before. I have a web application that requires the user to select an item from a pulldown. The first input is a Lot number. The info to build the select list is generated via an MySQL query. Now, here's the thing. There are MANY items in the pulldown (1,000) which is not practical. I would like to run a query modified by the string they put in the first input box. I'm trying to avoid a page reload. So, Here is the input box <input name="lotno" /> Here is the basic pulldown code: echo "<option value='void'>--- Select a test ---</option>";$sql='SELECT distinct `test_templates`.`tempid`, concat(`test_templates`.`assy`," - ",`test_templates`.`testdesc`) as DescriptionFROM `test_templates` ORDER BY `assy` ASC';$result = mysql_query($sql); while($row=mysql_fetch_array($result)){ echo "<option value='".$row[0]."'>"; echo $row[1]; echo "</option>"; }} I would change the above SQL with ...WHERE `lot` like WHATEVER IS IN THE lotno input field. Then the result of the query would be very limited. Thanks in adanced. Quote Link to comment https://forums.phpfreaks.com/topic/282724-dynamic-pulldown/ Share on other sites More sharing options...
fastsol Posted October 5, 2013 Share Posted October 5, 2013 Here is a tutorial I have that will give you the basic idea of how to use the ajax thing and populate the select box. You will need to do some modification of the tutorial to work with the input textbox rather than only select boxes. The one issue that you will have to decide on is when to actually populate the select box, meaning do you do it with every keypress in the textbox or only after so many characters or on focus out, etc. A select box is a simple thing cause you know for sure when they have selected something cause the value changes when onclick on a item, but a textbox is always changing as you type and you don't really know when they are done typing. http://amecms.com/article/Building-Chained-Select-Boxes-with-Jquery-and-PHP Quote Link to comment https://forums.phpfreaks.com/topic/282724-dynamic-pulldown/#findComment-1452649 Share on other sites More sharing options...
AV1611 Posted October 5, 2013 Author Share Posted October 5, 2013 Thank you. Unfortunately the tutorial doesn't answer my question. 1. I don't know AJAX 2. While I know many disagree, I don't need to use jQuery, and have no idea how to use it. Please let's don't argue about that. 3. When I fill in the initial < input type = text > I assume I need to do onChange = myFunction() 4. so I really need to know how to write myFunction. I can write the PHP script that gets queried by myFunction. Your tutorial, aside from using Jquery which I don't really understand, drives a pulldown from another pulldown , I think... I am 6 months into this project, and don't really want to change to jQuery at this point. Quote Link to comment https://forums.phpfreaks.com/topic/282724-dynamic-pulldown/#findComment-1452708 Share on other sites More sharing options...
fastsol Posted October 5, 2013 Share Posted October 5, 2013 If you can do PHP you can do jquery, it has similar syntax. The only thing you need to be able to use jquery is a link in your <head> to the jquery library file like I have in the tutorial. You can certainly do this without jquery, but why, jquery makes life so much easier and it's still just javascript like it would be without using jquery. You can't make php run your myFunction(). The only way to do this without a page refresh is with ajax which jquery has easy functions for. I don't think you will find anyone to build this for you, so your going to have to try some things and post back with any issues you are having. The tutorial is very simple and commented well, just strip it down to what you need and go from there. At that point google some things on how to do the rest, it's really not hard. I was scared of javascript/jquery for a long time until I actually tried it and found it to be so easy it was crazy. My 2 cents worth, good luck. Quote Link to comment https://forums.phpfreaks.com/topic/282724-dynamic-pulldown/#findComment-1452711 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.