javascript - Dependent dropdown list working in php and not working in codeigniter -
in below code when worked in php dropdown working when exam name selected corresponding course_code came , when selected corresponding subject_code came.but created controller , call view in codeigniter when select exam_name not populating values , when click upload shows course_code values , not populating subject_coide , when click upload populates subject_code.so pls me.
upload1_site (controller) <?php class upload1_site extends ci_controller { function index() { $this->load->view('new_view'); } function upload() { $this->load->view('new1_view'); } }//end of class ?> new_view (view 1) <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".hai").change(function() { var id=$(this).val(); // please find course_code, course_code not found var datastring = 'course_code='+ id; $.ajax ({ type: "post", url: "upload1_site/upload", data: datastring, cache: false, success: function(html) { $(".hai2").html(html); } }); }); $(".hai2").change(function() { var id2=$("#hai2").val(); alert(id2); var datastring = 'subject_code='+ id2; $.ajax ({ type: "post", url: "upload1_site/upload", data: datastring, cache: false, success: function(html) { $(".hai3").html(html); } }); }); }); </script> </head> <form enctype="multipart/form-data" action="<?php echo $_server['php_self']; ?>" method="post"> file import: <input size='30' type='file' name='filename'> <br> select exam name: <select name="hai" class="hai" id="hai"> <?php mysql_connect("localhost", "root", "") or die("error connecting database: ".mysql_error()); mysql_select_db("slseatapp") or die(mysql_error()); $query="select distinct exam_name examcourse"; $result = mysql_query($query); while($nt=mysql_fetch_array($result)) { echo "<option value='".$nt['exam_name']."'>".$nt['exam_name']."</option>"; } ?> </select> <br> <span class="hai2"> course code: <select name="hai2" id="hai2"> <?php if($_request['hai']){?> <option>select</option> <?php $query="select distinct course_code examcourse exam_name = '".$_request['hai']."' "; $result = mysql_query($query); while($nt=mysql_fetch_array($result)) { echo "<option value='".$nt['course_code']."'>".$nt['course_code']."</option>"; } ?> <?php }else{?> <option>select</option> <?php }?> </select> </span> <br> <span class="hai3"> subject code: <select name="hai3" id="hai3"> <?php if($_request['hai2']){?> <option>select</option> <?php $query="select distinct subject_code coursesubject course_code = '".$_request['hai2']."'"; $result = mysql_query($query); while($nt=mysql_fetch_array($result)) { echo "<option value='".$nt['subject_code']."'>".$nt['subject_code']."</option>"; } ?> <?php }else{?> <option>select</option> <?php }?> </select> </span> <br> <input type="submit" name="submit" value="upload"></form> <?php mysql_connect("localhost", "root", "") or die("error connecting database: ".mysql_error()); mysql_select_db("slseatapp") or die(mysql_error()); //upload file if (isset($_post['submit'])) { if (is_uploaded_file($_files['filename']['tmp_name'])) { //import uploaded file database $row = 1; $handle = fopen($_files['filename']['tmp_name'], "r"); $var = $_post['hai']; $var2 = $_post['hai2']; $var3 = $_post['hai3']; //$res=mysql_fetch_array(mysql_query("select subject_code coursesubject course_code = '".$var1."'")); while (($data = fgetcsv($handle, 1000, ",")) !== false) { //update database values $import="insert student_table (id,register_number,name,course_code,subject_code,exam_name) values('".mysql_real_escape_string($data[0])."', '".mysql_real_escape_string($data[1])."','".mysql_real_escape_string($data[2])."','$var2','".$var3."','$var')"; //$import="replace student_table (id,register_number,name,course_code,subject_code,exam_name) values('".mysql_real_escape_string($data[0])."', '".mysql_real_escape_string($data[1])."','".mysql_real_escape_string($data[2])."','$var','$var1','$var2')"; mysql_query($import) or die(mysql_error()); } fclose($handle); echo"<script>alert('uploaded successfully');</script>"; }else{ echo"<script>alert('failed');</script>"; } } ?> new2_view (view 2) <script language="javascript"> function changeselection(value){ var length = document.getelementbyid("hai3").options.length; if(value == 0){ for(var = 1;i<length;i++) document.getelementbyid("hai3").options[i].selected = "selected"; document.getelementbyid("hai3").options[0].selected = ""; } } </script> <?php mysql_connect("localhost", "root", "") or die("error connecting database: ".mysql_error()); mysql_select_db("slseatapp") or die(mysql_error()); if($_post['course_code']){ @$exam_name=$_post['course_code']; ?> course code: <select name="hai2" id="hai2"> <option >select</option> <?php $query="select distinct course_code examcourse exam_name = '$exam_name' "; $result = mysql_query($query); while($nt=mysql_fetch_array($result)) { echo "<option value='".$nt['course_code']."'>".$nt['course_code']."</option>"; } ?> </select> <?php } if($_post['subject_code']){ @$subject_code=$_post['subject_code']; ?> subject code: <select name="hai3" multiple onchange="changeselection(this.value)" id="hai3"> <option value="0">select</option> <?php $query="select subject_code coursesubject course_code = '".$subject_code."'"; $result = mysql_query($query); while($nt=mysql_fetch_array($result)) { echo "<option value='".$nt['subject_code']."'>".$nt['subject_code']."</option>"; } ?> </select> <?php }?>
try one
put one
var base_url="<?=base_url()?>"
somewhere inside script tag may before
$(document).ready(function(){
line
and change line
url: "upload1_site/upload",
with
url: base_url+"upload1_site/upload",
please let me know if works or not.
Comments
Post a Comment