Solved

php onchange dropbox

Posted on 2010-08-31
8
869 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 …

863 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

21 Experts available now in Live!

Get 1:1 Help Now