473,413 Members | 2,051 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,413 software developers and data experts.

Two drop down boxes in php and mysql

250 100+
In my application I have two drop down boxes. 2nd drop down box should filled according to the selected value on the 1st drop down box. But My 2nd drop down box not update.This is my code

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     function showSelected(val){
  3.         document.getElementById('selectedResult').innerHTML = "The selected number is - " + val;
  4.     }
  5.     function show(val){
  6.         document.getElementById('model').innerHTML = "The selected number is - " + val;
  7.     }
  8. </script>
  9. <td>Make :</td> 
  10. <td>
  11.  
  12. <select name="make"  class="normalTxt" onChange='showSelected(this.value)' >
  13. <?php    $mysql_result1 = mysql_query("SELECT DISTINCT vehicleMake FROM  vehicles");
  14. while($row = mysql_fetch_array($mysql_result1)){
  15. foreach( $row AS $key => $val )
  16. $Make = stripslashes( $val );
  17.  
  18. ?>
  19. <option  value=<?php  echo  "'$Make'" ?> ><?php echo "$Make&nbsp;&nbsp;&nbsp;"?>
  20.  <?php 
  21.     }    
  22. ?>
  23.  </option>
  24. </select>
  25.  <?php
  26.  
  27. ?>
  28. </td>
  29. <div id='selectedResult'></div>
  30.  
  31.   <td>Model :</td> 
  32.     <td>
  33.  
  34.  
  35. <select name="vehicleModel" class="defaultBlackText" onChange='show(this.value)'>
  36. <option value="Select" selected="selected">Select</option>
  37. <?php
  38.  
  39. $qq = mysql_query("SELECT * FROM vehicles WHERE vehicleMake= '".$Make."' ");
  40. while($row = mysql_fetch_array($qq)){
  41. foreach( $row AS $key => $val ){
  42. $$key = stripslashes( $val );
  43. }?>
  44. <option> <?php 
  45. echo "$vehicleModel"; 
  46. ?> 
  47. </option>
  48. <?php }
  49. //}?>
  50.  
  51. </select>
  52. </td>
  53. <div id='model'></div>
  54.  
Please help me..
Jul 15 '11 #1
1 2243
Rabbit
12,516 Expert Mod 8TB
PHP does not run on the client side. Either you have to submit the page to itself and pass the value that was selected or you send an HTTP request to a different PHP page that will return the values. The first option is easier but forces a refresh of the entire page every time the user selects a make. The second option requires more javascript and an additional PHP page but is more fluid.
Jul 15 '11 #2

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

Similar topics

0
by: Leigh | last post by:
I am building a data entry application using Java servlets. I had hoped to use drop down boxes to provide the user with data entry selections pulled from a database, but am now questioning, given...
5
by: MasterChief | last post by:
I have 3 drop down boxes on the same page. Each one is being populated by a database. One is called Location, One is called Device and the other one is called Job Title. When the user selects...
7
by: callawayglfr | last post by:
I am building a database in access where I have a drop down box that relates to a text box, that part I have working but when someone selects information from the first drop down I need it to limit...
2
by: ckerns | last post by:
I have a page with a bunch of drop down boxes. They are named: MonEquipAMWk1 MonEquipPMWk1 thru FriEquipAMWk1 FriEquipPMWk1
4
by: teknoshock | last post by:
I have created a page with multiple drop down boxes, all populated with the same options. My problem is, for 12 dropdown boxes and 40 choices per box, I end up with a massive file. Also, if I...
5
by: dynamitez | last post by:
Hi there, I need some help! I want to create 2 dependent dynamic drop down boxes which choices of box 2 depends on the choice chosen from box 1. Ex. Box1 -western -eastern Box2 (If...
3
by: amcoldspy | last post by:
Hi, am trying to create dynamic drop down boxes.. there are 3 drop down boxes. The second drop down box elements are to be update based on the selection made in the first drop down box...
10
by: kashhere | last post by:
hi all, i had two drop down boxes on the selection of one item in the first drop down box the related items should be changed in the second one can any one please suggest me towards the solution...
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
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...

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.