Hi

Can any one please help me on the below issue.

i can able to display values for texbox. but i don't know how to load the values for

<div id='txtHint' name='ptype'></div>

and if i change any value in conn_type it has to display.

test.php

<form action="<?php $_PHP_SELF ?>" method="post" enctype="multipart/form-data">
  <table>
  <tr>
    <td>Line Number</td>
    <td><input type='text' name='flag_seq' required id='flag_seq'/></td>
  </tr>
  <tr>
    <td>Connection Type</td>
    <td><input type='text' name='conn_type' id='conn_type' onChange='showptype(this.value)'></td>
  </tr>
  <tr>
    <td>Type</td>
    <td><div id='txtHint' name='ptype'></div></td>
  </tr>
</table>
</form>
 <script type="text/javascript">

function showptype(str1)
{
if (str1=="")
  {
  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","getptype.php?q="+str1,true);
xmlhttp.send();
}
</script>

getptype.php

$q=strtoupper($_GET['q']);

$query="select * from $database.FQ64006 WHERE SCYQ64CTYPE='$q'";
$result = oci_parse($connection,$query);
oci_execute ($result,OCI_DEFAULT);
$ex1=oci_fetch_array($result,OCI_BOTH);
if($q!='')
{
?>

<input type="text" name="ptype" id="ptype" value="<?php $SCYQ64TYPE1 = $ex1["SCYQ64TYPE"]; echo $SCYQ64TYPE = trim($SCYQ64TYPE1) ?>" readonly >
<?php } ?>

Recommended Answers

All 4 Replies

I want to display the values from databse in

<div id='txtHint' name='ptype'></div>

Have you thought about using jquery? jQuery's ajax function is really easy and can get your task done very quickly. Just a suggestion, I know some people like to use thier own code and not use libraries. Here is a sample of ajax call.

sample:

$(document).ready(function(){
    $('input[type="submit"]').on('click', function($){
        e.preventDefault();

        $.ajax({
            url:'getptype.php',
            type:'POST',
            data: $('form').serialized(),
            cache:false,
            success: function(data){
                $('#textHint').html(data);
            }   
        });
    });
});

you need to echo this whole thing

<input type="text" name="ptype" id="ptype" value="<?php $SCYQ64TYPE1 = $ex1["SCYQ64TYPE"]; echo $SCYQ64TYPE = trim($SCYQ64TYPE1) ?>" readonly >

and this one

if($q!='')

should be written like this

if($q!=='')

Alternatively, Gabriel is correct about JQuery option. It is a lot easier to use jquery libraries.

Hi

i changed my code as below

tt.php

<?php
session_start();
include('conn.php');

$sid = $_GET['sid'];
$lnid = $_GET['lnid'];
$lnid1=$lnid/1000;

    $sqlsid = "select * from $database.FQ64002 where SDYQ64SID='$sid' and SDYQ64LNID='$lnid'";
    $rowsid = odbc_exec($connection,$sqlsid);

    $SDYQ64CTYPE1 = odbc_result($rowsid,"SDYQ64CTYPE"); 
    $SDYQ64CTYPE = trim($SDYQ64CTYPE1);

    $SDYQ64TYPE1 = odbc_result($rowsid,"SDYQ64TYPE"); 
    $SDYQ64TYPE = trim($SDYQ64TYPE1);
?>
<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()
{
$(".country").change(function()
{
var id=$(this).val();
var dataString = 'id='+ id;

$.ajax
({
type: "POST",
url: "ajax_city.php",
data: dataString,
cache: false,
success: function(html)
{
$(".city").html(html);
} 
});

});

});
</script>
<!-- HTML Code -->
Conn Type : <select name="country" class="country">
<?php
$sql="select * from $database.FQ64006";
$result = odbc_exec($connection,$sql);
while(odbc_fetch_row($result))
{
$SCYQ64CTYPE12 = odbc_result($result,"SCYQ64CTYPE");
$SCYQ64CTYPE2 = trim($SCYQ64CTYPE12);
?>
<option value="<?php echo $SCYQ64CTYPE2;?>" <?php if($SCYQ64CTYPE2==$SDYQ64CTYPE){?>selected="selected"<?php } ?>><?php echo $SCYQ64CTYPE2; } ?></option>
</select> <br/><br/>

PType :<select name="city" class="city">
<option>select PTYPE</option>
</select>

ajax_city.php

<?php
include('conn.php');

if($_POST['id'])
{
echo $id=$_POST['id'];
echo $query="select * from $database.FQ64006 WHERE SCYQ64CTYPE='$id'";
$result = odbc_exec($connection,$query);
{
 $SCYQ64TYPE1 = odbc_result($result,"SCYQ64TYPE");
 $SCYQ64TYPE = trim($SCYQ64TYPE1);
?>
<option value="<?php echo $SCYQ64TYPE;?>"><?php echo $SCYQ64TYPE; ?></option>
<?php } } ?>

but when i was editing the screen. i am not able to get default value in ajax_city.php

pleae help me

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.