Dear Sanjeev,

you're right. I am sorry for my carelessness. I corrected my code and than try 
it again. But again, it does not work as I expect.

I even put << prompt("this function is being called"); >> in the jsopsi() but 
again the prompt does not come out. Pffuih... I am desperate only because of 
this small thing.

Please keep telling me what's wrong with my code. Do I have to write the 
JavaScript in another way if the javascript is placed in php file?
==
//This is my current code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<HTML>
<HEAD>
  <META name="generator" content="HTML Tidy for Linux/x86 (vers 31 October 
2006), see www.w3.org">

  <TITLE>guru.com - Menu for new customer</TITLE>

<Script Language="JavaScript">
function jsopsi(){
prompt("This prompt comes out if this function is really being called");
if (document.formulir.opsinegara.value!="Virgina Islands (USA)";){
        document.formulir.opsistate.options[5].selected=true;
}
}
</Script>
</head>
<BODY>
<?php
if (isset($pid)){
        $idproduk=$_GET['pid'];
        echo "Produk ID: $idproduk<br>";
}
?>

<table border=0 align="center" cellpadding=0 cellspacing=0 width=800>
<tr><td></td><td><table border=0 align="center" cellpadding=0 cellspacing=0 
width=400>
<form method="post" action="cgi/cgipelangganbaru.php?pid=$idproduk" 
name="formulir">
<tr>
        <td align="right" bgcolor="#F5D78B">
        3. Country:
        </td>
        <td align="center">
        </td>
        <td align="left">
        <select name="negara" onchange="jsopsi()" name="opsinegara">
        <?php
        include_once "koneksi.php";
        $sqlnya="select country from countries";
        $kelas=new koneksi();
        $klas=$kelas->getkoneksi("survey",$sqlnya);
        if ( mysql_num_rows($klas) > 0 ) {
        while( list($negara) = mysql_fetch_row($klas) ) {
                echo "<option id=\"opsi"."$negara\" 
value=\"$negara\">$negara</option>";
        }
        } else {
                echo 'No results found';
        }
        ?>
        </select>
        </td>
</tr>
<tr>
        <td align="right" bgcolor="#F5D78B">
        4. State:
        </td>
        <td align="center">
        </td>
        <td align="left">
        <select name="opsistate">
        <?php
        include_once "koneksi.php";
        $sqlnya="select state,statename from states";
        $kelas=new koneksi();
        $klas=$kelas->getkoneksi("survey",$sqlnya);
        if ( mysql_num_rows($klas) > 0 ) {
        echo "<option name=\"state\" value=\"\"></option>";
        while( list($state,$statename) = mysql_fetch_row($klas) ) {
                echo "<option name=\"state\" value=\"$state\">$statename 
($state)</option>";
        }
        } else {
                echo 'No results found';
        }
        ?>
        </select>
        </td>
</tr>
</form>
</table>
</td><td></td></tr></table>
</BODY>
</HTML>
==
On Sat, 25 Aug 2007 22:26:49 +0530
"Sanjeev N" <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> JavaScript codes works in php files. Yours code is also fine. 
> But check your calling function and defined functions. Calling function is
> jsopsi and defined function is opsi. Please check. Other than this
> everything is ok
> 
> Warm Regards,
> Sanjeev
> http://www.sanchanworld.com/
> http://webdirectory.sanchanworld.com - Submit your website URL
> http://webhosting.sanchanworld.com - Choose your best web hosting plan
> -----Original Message-----
> From: Patrik Hasibuan [mailto:[EMAIL PROTECTED] 
> Sent: Saturday, August 25, 2007 9:17 PM
> To: php-general@lists.php.net
> Subject: [PHP] Does JavaScript not work in php web file?
> 
> Dear my friends...
> 
> I am confused to implement JavaScript code in php web file.
> 
> I want my JavaScript change the "selected" item of <select> tag based on the
> "selected" item of previous <selected> in same php page.
> 
> Please help me.... tell my where is my mistake.
> 
> ===
> Here is my code pelangganbaru.php
> ===
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> 
> <HTML>
> <HEAD>
>   <META name="generator" content="HTML Tidy for Linux/x86 (vers 31 October
> 2006), see www.w3.org">
> 
>   <TITLE>guru.com - Menu for new customer</TITLE>
> </HEAD>
> <Script Language="JavaScript">
> function opsi(){
> if (document.formulir.opsinegara.value!="Virgina Islands (USA)";){
>       document.formulir.opsistate.options[0].selected=true;
> }
> }
> </Script>
> 
> <BODY>
> <?php
> if (isset($pid)){
>       $idproduk=$_GET['pid'];
>       echo "Produk ID: $idproduk<br>";
> }
> ?>
> 
> <table border=0 align="center" cellpadding=0 cellspacing=0 width=800>
> <tr><td></td><td><table border=0 align="center" cellpadding=0 cellspacing=0
> width=400>
> <form method="post" action="cgi/cgipelangganbaru.php?pid=$idproduk"
> name="formulir">
> <tr>
>       <td align="right" bgcolor="#F5D78B">
>       3. Country:
>       </td>
>       <td align="center">
>       </td>
>       <td align="left">
>       <select name="negara" onchange="jsopsi()" name="opsinegara">
>       <?php
>       include_once "koneksi.php";
>       $sqlnya="select country from countries";
>       $kelas=new koneksi();
>       $klas=$kelas->getkoneksi("survey",$sqlnya);
>       if ( mysql_num_rows($klas) > 0 ) {
>       while( list($negara) = mysql_fetch_row($klas) ) {
>               echo "<option id=\"opsi"."$negara\"
> value=\"$negara\">$negara</option>";
>       }
>       } else {
>               echo 'No results found';
>       }
>       ?>
>       </select>
>       </td>
> </tr>
> <tr>
>       <td align="right" bgcolor="#F5D78B">
>       4. State:
>       </td>
>       <td align="center">
>       </td>
>       <td align="left">
>       <select name="opsistate">
>       <?php
>       include_once "koneksi.php";
>       $sqlnya="select state,statename from states";
>       $kelas=new koneksi();
>       $klas=$kelas->getkoneksi("survey",$sqlnya);
>       if ( mysql_num_rows($klas) > 0 ) {
>       echo "<option name=\"opsi".$state."\" value=\"\"></option>";
>       if ($negara=="Virgin Islands (US)"){
>               echo "<option name=\"nonusa\" value=\"00\" selected>Non
> USA</option>";
>       }else{
>               echo "<option name=\"nonusa\" value=\"00\">Non
> USA</option>";
>       }
>       while( list($state,$statename) = mysql_fetch_row($klas) ) {
>               echo "<option name=\"state\" value=\"$state\">$statename
> ($state)</option>";
>       }
>       } else {
>               echo 'No results found';
>       }
>       ?>
>       </select>
>       </td>
> </tr>
> <tr>
>       <td align="right">
>       <input type="submit">
>       </td>
>       <td align="center">
>       </td>
>       <td align="left">
>       <input type="reset">
>       </td>
> </tr>
> </form>
> </table>
> </td><td></td></tr></table>
> </BODY>
> </HTML>
> -- 
> Patrik Hasibuan <[EMAIL PROTECTED]>
> Junior Programmer
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 


-- 
Patrik Hasibuan <[EMAIL PROTECTED]>
Junior Programmer

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to