473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to parse a function's result to php select dropdown value property.

Dear pros, I have 2 select option comboboxes on the form. One combo box reads data from mysql on pageLoad event.
OnChange of the selected option, php should read another data from mysql into the second combo box.
The second read-data should be in a function (not necessarily, just if there is a simpler way to do it). But please check the code below: Thank you!

Expand|Select|Wrap|Line Numbers
  1. <form name="form1" action="confirm_zone.php" method="post" style="margin-left:15px; margin-right:20px;">
  2.         <p><b style="color:#990000;">Select / Choose your Region:</b>
  3.  
  4. <?php
  5. //this code reads first data from mysql and populate 
  6. //combo box 1.
  7. //this is where the onChange event will come in.
  8.  
  9. $load_region = mysql_query("SELECT region_number FROM region ORDER BY region_number");
  10. echo "<Select name='region' size='1' onChange='". read($data)  ."'> ";//read($data) is a presumed function
  11.  
  12. while ($row = mysql_fetch_array($load_region)) {
  13.   echo '<option value="'. $row['region_number'] .'">' . $row['region_number'].'</option>'; } 
  14. echo "</select> ";
  15. ?>
  16.  
  17. &nbsp;&nbsp;&nbsp;&nbsp;
  18. <b style="color:#990000;">Select your Province:</b>
  19.  
  20. <?php
  21. //this should be the function.
  22. function read($data) {
  23.  
  24. $dropdown ="<Select name='province' size='1'> ";
  25. $load_province = mysql_query("SELECT province_number, province_location FROM province ORDER BY province_number");
  26.  
  27. while ($row = mysql_fetch_array($load_province)) {
  28. $dropdown .= "\r\n<option value='{$row['province_location']}'" . "-{$row['province_number']}>" ."{$row['province_location']}" . " {$row['province_number']}".  "</option>"; }
  29.  
  30. $dropdown .= "\r\n</select>";
  31. echo $dropdown."<br>";
  32. }
  33. ?> <!-- end of function -->
  34.  
Thank you!
Apr 8 '13 #1
3 1718
Rabbit
12,516 Expert Mod 8TB
You'll need to use an AJAX request for that. Here is a link to an AJAX tutorial: http://www.w3schools.com/ajax/
Apr 8 '13 #2
how will I combine AJAX with php to read from mysql database?
How is that possible?
Apr 8 '13 #3
Rabbit
12,516 Expert Mod 8TB
It shows you how in the tutorial.
Apr 8 '13 #4

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

Similar topics

3
by: Northern | last post by:
I have an ASP DropdownList populated. What I want is to select a new item, in my code, by set a datavale to dropdownlist's selectedItem.Value property. I did the following: ...
1
by: Olivier Sanzot | last post by:
Hi, I'd like to find a multi-select dropdown for asp.net. Has someone some tips ? Thanks, Olivier.
2
by: Monty | last post by:
I use a SELECT dropdown as the nav interface for jumping to a chosen page number. When I setup up the SELECT element on the page, I want to show the user the current page number they are on, so, I...
2
by: Dan Puskar | last post by:
Hi. I'm new to this forum & to PHP. Just have a little problem. I want to pass the value of a select box to a php script on another page. Here's the code: $output .= "<select name =...
21
by: Steven T. Hatton | last post by:
I'm trying to improve my formal understanding of C++. One significant part of that effort involves clarifying my understanding of the vocabulary used to describe the language. This is from the...
2
by: Wolfgang | last post by:
Hi, is there a possibility to change the size of the select-dropdown-box ? I predefine the length of the option-area with 10 inside HTML as follows: <select class="select250"...
6
by: idj | last post by:
Hi, I'm using the following code to redirect to a new page with a select dropdown, which works fine: <script type="text/javascript"> <!-- function go(){ location= document.FRM_NAME.VALUE_NAME....
0
acoder
by: acoder | last post by:
Problem The select object's add method doesn't append options to the end of the list. Browser Internet Explorer Example The Javascript code for appending an option element at the end of a...
2
by: Tony Johansson | last post by:
Hello! What purpose has this Value propery on nullable types because it possible to display their value without using it. For example: int? intNullable1 = 3; int? intNullable2 = 5;...
1
by: nawedita | last post by:
Hi I am facing a problem with my code .... this is what I am doing ... I am running this dropdown in while loop...and i want when i select Cheque then display textbox otherwise textbox not...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.