Jump to content

Problem on : PHP Code within Javascript code ?


yusufhermanto

Recommended Posts

Hello all,

i'm new on php programming, and i have problem about this.

i have code like this :

 

<script language="JavaScript">

function Displaydata()

    {

        var kdcust = document.frmpo.cbocust.value;

        alert(kdcust);

        <?

        $kd= document.frmpo.cbocust.value;

 

        $s="select * From customer where kd_cust='".$kd."'";

        $rs = mysql_query($s);

        $row=mysql_fetch_array($rs,MYSQL_BOTH);     

       

        ?>

 

        document.getElementById("telp").value='<? echo $row["telp"]; ?>';

    }

</script>

 

i want to get data from  "document.frmpo.cbocust.value" object.

and i try enter on $kd variable :

$kd= document.frmpo.cbocust.value;

 

but i can not get data from this dasta.

 

what is wrong with my code ?

please help me :(

 

thanks

Javascript is working on you Browser. So that has nothing to do with PHP.

PHP is a language for the Server. When you get to a PHP-File you don't see any codes.

 

What you're trying to do is getting data to use it to get another information of mysql.

AJAX will help you

Javascript is working on you Browser. So that has nothing to do with PHP.

PHP is a language for the Server. When you get to a PHP-File you don't see any codes.

 

What you're trying to do is getting data to use it to get another information of mysql.

AJAX will help you

 

yes i want to automatically display data from mysql when i get code from database.

this step of my scrpt:

1. display data from to Drop Down Box and this mycode :

 

<td width="45%" height="19"><select size="1" name="cbocust" onChange='Displaydata()'>

      <?

        $rs = mysql_query("select nm_cust,kd_cust from customer order by kd_cust");

        $b=0;

        while($row=mysql_fetch_array($rs,MYSQL_BOTH)){

            $b++;

            echo "<option value=".$row["kd_cust"].">".$row["nm_cust"]."</option>";

        }

        ?>

      </select></td>

 

2. and then i want to display automatically all data from customer data when choose value of cbocust ( the code on the above posted)

 

 

do you have other solution for my problem ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.