Hi every one. I have a problem with combinning two scripts.
Fisrt script is working perfectly and taking stuf from mysql:

    function showUser(str)
        {
        if (str=="")
          {
          document.getElementById("txtHint").innerHTML="";

          return;
          } 
        if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
          }
        else
          {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        xmlhttp.onreadystatechange=function()
          {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
            document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
            }
          }
        xmlhttp.open('GET','includes/test-search.php?q='+str,true);
        xmlhttp.send();

        }
    </script>

The second one is working perfectly and it's simple script for inserting data after change:

<script type="text/javascript">
    $("document").ready(function(){
        $("#selection").change(function () {
        $("#someDivName").html( $("#selection option:selected").val() );
    });
    });
    </script>

now the hole point is to combine them.
It's look like, when I load the site it don't have id selection and second script stops but after taking data from php and mysql file test-search.php the missing id selection is on site but the first script is not checking if id selection apear and don't work.

The php code:

<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', 'root', '');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("table", $con);

$sql="SELECT * FROM prod_models WHERE prod_main_group_id = '".$q."'";

$result = mysql_query($sql);

echo '
<select id="selection" name="prod_main_group_id" onchange="change_val()">
<option value="">Wybierz produkt</option>
';

while($row = mysql_fetch_array($result))
  {
  echo '<option value="'.$row['id'].'">';
  echo $row['product_name'] . "</option>";

  }
echo "</select>

";

mysql_close($con);
?>

Code to display changed script:

<input type="text" id="someDivName" value="" />

if any one can help with solving the problem will be realy nice.
Thx i'm waiting for it now and trying to solve this for my self but now I don't have other ideas for it.

I have solved my problem.

<select id="selection" name="prod_main_group_id" onchange="$(\'#someDivName\').val($(\'#selection option:selected\').text())">
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.