Solved

php onchange dropbox

Posted on 2010-08-31
8
887 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 109

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
 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

820 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