Welcome Guest, Not a member yet? Register   Sign In
Variable JQuery(JS) with PHP (transferring data in variables)
#1

[eluser]Unknown[/eluser]
Hello Everyone,

I'm currently working on a dropdown where once that is changed the values for the other option boxes will change. I'm currently confused on how to pass the value from the first dropdown.

This is what i have at the moment

JS
Code:
$(document).ready(function() {
('#country').change(function(){
var stateprovince = $(this).attr('value');

$.post('index.php/user/seconddp',{ stateprovince: stateprovince}, function(data) {
   $('#feedback').html(data);
   $(data).each(function(index, item) {
   $('#stateprovince').append('<option>' + item.stateprovince + '</option>');

   });
  });

});  

});


controller
Code:
function seconddp() {
  
   if (isset($_POST['stateprovince'])){
    $stateprovince = $_POST['stateprovince'];
    }
    
  $statesprovinces = $this->Usermodel->find_seconddp($stateprovince);
   echo json_encode ($statesprovinces) ;
  }


Iam confused on how to pass the data through variables with JS and PHP :-S, Can someone show me a example on how it would be done?




Theme © iAndrew 2016 - Forum software by © MyBB