Solved

php onchange dropbox

Posted on 2010-08-31
8
878 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Selecting SUM data from mysql table with PHP 4 19
UPDATE query not working in mysqli php 8 50
ebay devID, appID, certID, userToken 2 27
Cpanel file manager 8 23
This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
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…

770 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