1

i want to pass more than two value from view to controller using javascript based on dropdown value! here are my codes

<select name="class" id="class">
   <option selected value='-1'>--Select class--</option>
   <?php foreach($classes as $class){ 
      echo '<option value="'.$class['class_id'].'">'.$class['class_name'].'</option>'; }
      ?>
</select>
<select name="subject" id="subject">
   <option selected value='-1'>--Select Subject--</option>
   <?php 
      foreach($subjects as $subject) {                       
        echo '<option value="'.$subject['subject_id'].'">'.$subject['subject_name'].'</option>';
      }
      ?>
</select>
<script type="text/javascript">
   $(document).on("change","#class",function(e){
   e.preventDefault();
   var classid = $(this).val(); 
   $.post('<?php echo  site_url("system_ctrl/select_student"); ?>',{"class_id":classid},function(responce){
   $("#names").html(responce);
   });
</script>

i want to send value of id subject together with value of id class to the controller when value of class changes using javascript shown above.

1
  • you can pass N number of values like this {"class_id":classid,"subject":subject_id } Commented Feb 8, 2017 at 10:39

2 Answers 2

1

You can pass any number of values like this,

$.post('<?php echo  site_url("system_ctrl/select_student"); ?>',{"class_id":classid, "subject":$('#subject').val()},function(responce){
    $("#names").html(responce);
});
Sign up to request clarification or add additional context in comments.

Comments

0

$(document).on("change","#class",function(e){ e.preventDefault(); var classid = $(this).val(); $.post('',{"class_id":classid,"subject":$('#subject').val()},function(responce){ $("#names").html(responce); }); $(document).on("change","#subject",function(e){ e.preventDefault(); var subjectid= $(this).val(); $.post('',{"subject_id":subjectid,"class":$('#class').val()},function(responce){ $("#names").html(responce); });

2 Comments

may you arrange in a proper way please!
its not allowing me to arrange it. i dont know why. but your have to do make that javascript for the both of the select field. so that if you select subject directly. then it will work also and get the upper class data also

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.