Jump to content

Recommended Posts

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 Description
FROM `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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/282724-dynamic-pulldown/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/282724-dynamic-pulldown/#findComment-1452649
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/282724-dynamic-pulldown/#findComment-1452708
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/282724-dynamic-pulldown/#findComment-1452711
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.