Solved

php onchange dropbox

Posted on 2010-08-31
8
855 Views
Last Modified: 2013-12-13
I have a php page called "orders_edit_visit.php"
This has list box being fed names from a mysql record set and these names are customer names, called "txtName"
There is another list box on the same page called "selid" which is being fed from anothyer mysql database and contains all orders for customers

I need to be able to have some sort of OnChange event in the "txtName" field such that when a particular name is selected.
all the order ID's for that name are the only ones able to be selected from the  "selid" box
0
Comment
Question by:doctorbill
8 Comments
 
LVL 4

Accepted Solution

by:
darkyin87 earned 375 total points
ID: 33569102
I will be using AJAX to do this functionality. For more information just read through this article it will help you to figure it out.

http://roshanbh.com.np/2008/01/populate-triple-drop-down-list-change-options-value-from-database-using-ajax-and-php.html
0
 

Author Comment

by:doctorbill
ID: 33569482
is there an alternative to this ?
0
 
LVL 4

Assisted Solution

by:darkyin87
darkyin87 earned 375 total points
ID: 33569658
This is the way I know to do it. If you have difficulties following the instructions in the other page refer this page. It helps you to create the code for double list box.

http://phpcode.hu/teszt/jquery_select/
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 33572535
There are ways to do it without AJAX - preloading all the possible options as invisible DOM elements and rendering them visible when the first selection is made.  But I think the AJAX approach is better - faster for the client and easier to generalize the solution.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:doctorbill
ID: 33575937
darkyin87:
Please can you giver me some idea of how to use the 4 pages - I am not so clued up on java
0
 
LVL 4

Assisted Solution

by:darkyin87
darkyin87 earned 375 total points
ID: 33578373
1) Enter the database details in the conndb.php file

2) The index.php file will populate the first list box for you by calling the createOptions function
   For this you will have to pass the tableName, the field that will be the value for the options and the
   field that will be the id for the options.
   
   For ex: In your case consider tableName as tableName, txtName_id as the id for each option and txtName
   as the value of the options.

3) select.php will help you to populate the second field. AJAX will query the select.php file everytime the
   option is changed in txtName passing it the value of the option selected as a GET variable. Now, select.php
   will call the createOptions passing it 4 variables the tableName, the field that will be the id for options,
   fieldName that will be the value for the options and the condition field if any.  
0
 

Author Comment

by:doctorbill
ID: 33585057
I have configured the conndb.php correctly
The table I need to use is called "orders" and I need to populate the select box with "CustName" from the table ordered by "ID". I have filled in the fields below but I think I have done it incorrectly:
-------------
include("conndb.php");
function createoptions($table , $id , $field)
{
    $sql = "select CustName from orders ORDER BY ID";
-------------
0
 
LVL 7

Assisted Solution

by:Vimal DM
Vimal DM earned 125 total points
ID: 33638566
Hai,

I have an option to tell you that, "ajax" would be the best way to make the combobox selection and select t he values in other combobox for the selected values


1) Ordinary mysql loaded combobox - have onchange option too
2) And for the another combobox take the below script

var xmlHttp

function showState(str)
{
      
xmlHttp=GetStateXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url="getcat.php";
url=url+"?q="+str;
//alert(url);
url=url+"&sid="+Math.random();

//alert(url);
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}

function GetStateXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
  catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  }
return xmlHttp;
}


In this page  "getcat.php" should have the another combobox design,request the sent values and select the values from the db and make the option values.


Thanks.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now