?
Solved

php onchange dropbox

Posted on 2010-08-31
8
Medium Priority
?
914 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Accepted Solution

by:
darkyin87 earned 1500 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 1500 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
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 
LVL 111

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 1500 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 500 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
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 …
Suggested Courses

777 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