Auto complete jquery used in loadBillingType.php page but not working auto complete jquery in this page why?

is Page Name Billing.php

<script type="text/javascript"> 
 function showbillingtype(str){ 
    if (str==""){
      document.getElementById("txtHint").innerHTML="";
      return;
    }
    if (window.XMLHttpRequest){
      xmlhttp=new XMLHttpRequest();
    }else{
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function(){
      if (xmlhttp.readyState==4 && xmlhttp.status==200){
        document.getElementById("txtHintBilling").innerHTML=xmlhttp.responseText;
      }
    }
    xmlhttp.open("GET","loadBillingType.php?q="+str,true);
    xmlhttp.send();
  }
</script>

<input type="radio" name="billing_type" onclick="showbillingtype(this.value)">

This Page Name loadBillingType.php

<script src="auto_fill/AFjquery.min.js"></script>
<link rel="stylesheet" href="auto_fill/AFjquery-ui.css">
<script src="auto_fill/AFjquery-ui.min.js"></script>
<script src="auto_fill/AFchosen.jquery.min.js"></script>
<link rel="stylesheet" href="auto_fill/AFchosen.min.css" type="text/css" />


<select name="billing_type_id" class="validate-selection" id="chosen" style="width:340px;">
<option value="" hidden="">Select Lab Name</option>
<? $select_doctor_list=mysql_query("select * from `insource_lab` order by `lab_name` asc");
  while($fetch_doctor_list=mysql_fetch_array($select_doctor_list)) {?>
<option value="<?=$fetch_doctor_list['id']; ?>"><?=$fetch_doctor_list['lab_name']; ?></option>
<? }?></select>

<script type="text/javascript">
  $autfile=$.noConflict(); 
  $autfile("#chosen").chosen();
</script>

You really need to format that code so it’s a bit more easy to read - it’s quite difficult to follow someone else’s code at the best of times, but when it’s formatted so badly, it’s just too much trouble.

Also noticed that the PHP code you use is using the old (no longer part of the language) mysql_query() function - could it be that your server is running PHP7 and that’s why it won’t work? I don’t see anywhere that you actually open a database connection - is that in an include file somewhere, and is it working correctly?

I am no expert on jQuery, but I don’t think you should be sticking all that HTML and JS code in your PHP file. To my mind, that all sits in the calling page, and when you call your PHP code via Ajax, it returns exactly what you will be inserting into the ready-formatted page, and nothing else. Doing it your way, you’re inserting all manner of tags and scripts into the middle of your page when the PHP is called. That doesn’t seem correct to me. I’m also a bit puzzled that you seem to mix old-style Ajax code and jQuery code - that’s not to say it won’t work, but why write all that out longhand when you can accomplish it more easily in jQuery?

What is happening that should not, or what is not happening that should? We need some more detail on exactly what the problem is and what steps you have taken to narrow it down.

Well the code in Billing.php could be replaced by a jquery ajax call, but other than that it’s not invalid.

I don’t like the idea of an on-click trying to load additional javascript libraries - so I would put those includes at the top of Billing.php instead…

That last line looks a little odd. Are you trying to use jquery there? Is $autfile predefined? if not you should have a var declaration in front of its first declaration. If it’s meant to be PHP, it’s not in a PHP block.

From a PHP standpoint, it looks solid, other than as has been pointed out to you that the mysql_ functions have been deprecated from 5.5 and removed from 7.0.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.