473,467 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

select option using onchange event in php

5 New Member
hi! i have a problem with my php code..
my question is by using these code..
--> how to make a state select then the branch will appear together if related?
hope my english is okay..hehe..

*negeri = state
*cawangan = branch

# if i select State JOHOR..auto the Branch of Johor will appear together..not all branch in Malaysia will appear..help me!!:'(

here my code:

Expand|Select|Wrap|Line Numbers
  1. <select name="NEGERI" class="select" id="NEGERI"> <option value ="0">-- Sila Pilih --</option> <?php
  2.                     //$sql = "SELECT * FROM negeri where FLAG=1 ORDER BY negeri ASC";
  3.                     $sql = "SELECT * FROM negeri WHERE  negeri_id = '".$NEGERI."'  FLAG=1 ORDER BY negeri ASC";
  4.                     $result_groups = mysql_query($sql);
  5.                     $result_group_member = mysql_numrows ($result_groups);
  6.                     if($result_group_number > 0)  {
  7.                         while ($myrow = mysql_fetch_array($result_group))  {
  8.                         if ($NEGERI == $myrow["negeri_id"])
  9.                             echo "<option value = ".$myrow["negeri_id"]." selected > ".$myrow["negeri"]."</option>\n";
  10.                         else "<option value =".$myrow["negeri_id"].">".$myrow["negeri"]."</option\n";
  11.                         }
  12.                         }
  13.                         ?>  
  14.      # cawangan = branch  #
  15.      <?
  16.                  $sql2 = "SELECT * FROM negeri_cawangan WHERE  cawangan_id = '".$CAWANGAN."'  FLAG=1 ORDER BY cawangan ASC";
  17.                  $result_groups2 = mysql_query($sql);
  18.                  $result_group_number2 = mysql_numrows2($result_groups2);
  19.                  if($result_group_number2 > 1) {
  20.                  while ($myrow2 = mysql_fetch_array($result_groups2)) {
  21.                     if ($CAWANGAN == $myrow2["cawangan_id"])
  22.                     echo "<option value=".$myrow2["cawangan_id"]." selected > ".$myrow["cawangan"]."</option>\n";
  23.                     else
  24.                     echo "<option value = ".$myrow2["cawangan_id"]." > ".$myrow2["cawangan"]."</option>\n";
  25.                     }
  26.                     }
  27.                     ?>
another question:
- where should i put the onchange event in this code?
Aug 22 '14 #1

✓ answered by Dormilich

where should i put the onchange event in this code?
in the JavaScript file.

how to make a state select then the branch will appear together if related?
you have to either fetch the according branch once the user selects the state or remove all unrelated branches from the list.

2 3319
Dormilich
8,658 Recognized Expert Moderator Expert
where should i put the onchange event in this code?
in the JavaScript file.

how to make a state select then the branch will appear together if related?
you have to either fetch the according branch once the user selects the state or remove all unrelated branches from the list.
Aug 23 '14 #2
KeyraRa
5 New Member
the branch and state have a own code.

*for state:
eg: JOHOR(01)
KEDAH (02)

*for branch:
eg: 01021011 JOHOR BAHRU
07041011 GEORGETOWN

1) so now in my code..where should i call the function?
2)how to write a onchange event and function call?
3)in Malaysia have many branch of each state..so should I write all the name of state and branch each? do you have a simple way?
Sep 11 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
10
by: Ryan McGeary | last post by:
In a <select> drop-down, the onchange event isn't called when scrolling through the dropdown using the mouse-wheel and when crossing over a new <optgroup>. Using the example below, notice how...
3
by: Santosh | last post by:
Hi, I have a requirement in which, I need to capture a loan amount and the amount of down payment for that loan. According to the requirement, the user is going to enter enter the loan amount and...
3
by: websphereguru | last post by:
I Have a text box in a jsp that is pre populated. The text box should accept only numbers and it should be greater than a minimum value (this value depends on the user settings). If the user enters...
4
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is...
3
by: b_naick | last post by:
I realize that the onChange event for a drop down can be trapped as follows: <select name="myDropDown" onChange="somefunc"> Is it possible to trap the onChange event outside of the select...
3
by: itp | last post by:
I have moved to Matt Kruse's Javascript Toolbox. It has some great examples to get you going quickly! Unfortunately all the examples are based on a form/submit model. I would like to try using...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
7
by: robtyketto | last post by:
Greetings, I'm slowly building up code to do the following:- Display TWO selection option boxes (cascading). If the FIRST selection option box changes then reload the jsp using onchange...
7
by: kirkgilbert | last post by:
I am trying to do an onchange event in a form using a text field. The form is tied to a record set that is part of a repeated region. One the first record when I edit the data it works perfectly. ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.