www.webdeveloper.com
Results 1 to 2 of 2

Thread: I want to change select value samilar to other select value

  1. #1
    Join Date
    Jul 2014
    Posts
    1

    I want to change select value samilar to other select value

    Hello
    I want to change <select> values samiler to other select value
    for example
    I choise honda from <select id="car"> got new values in <select id="model"> 1) civic 2) accord 3) ... etc
    and these models in database
    here my code

    HTML Code:
    <head>
    <script
    src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
    </script>
    <script type="text/javascript">
    	$(document).ready(function() {
    
        $("#make").change(function() {
    		var val = $(this).val();
    				
    		<?php
    		$result = mysqli_query($americacon,"SELECT * FROM cars WHERE make = val");
    		while($row = mysqli_fetch_array($result)) {
    		  ?> 
    		  $("#model").html("<option value='<?php echo $row['model']; ?>'><?php echo $row['model']; ?></option>");
    		  <?php
    		}
    		?>
    });
    </script>
    </head>
    <body>
    <select id="make">
    <option value="honda">honda</option>
    <option value="golf">Golf</option>
    </select>
    <select id="model">
    <option></option
    </select>
    </body>
    
    
    sorry for my english

  2. #2
    Join Date
    Feb 2014
    Location
    Managua, Nicaragua
    Posts
    45
    I recomend you to use ajax to get data from a database... You can not pass info or variables from js to php as you did. Var val does not exist when you do the query.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles