Javascript php sayfasında yayınlanmaz

5 Cevap php

Ben bir php sayfası var ve ben bazı alanlarda çalışan bir toplam sahip bazı javascript kodu var. i oldukça iyi i vardı ve bazı uygun kodu değiştirilmiş bir çalışma testi kopyalanmıştır. iyi çalışmıyor ve ben çalışmak için görünmüyor olabilir. Kaçırdığım blatently belirgin bir şey var veya çalışıyorsa değil neden başka bir neden var mı?

 <?php

 //server connection info

 ?>
 <html>
 <head>
 <title>Survey</title>
 <link rel="stylesheet" type="text/css" href="styles.css" />

       <script type="text/javascript">
           function Total()
           {

               var a=document.getElementById("a").value;
               var b=document.getElementById("b").value;
               var c=document.getElementById("c").value;
               var d=document.getElementById("d").value;

               a=parseInt(a);
               b=parseInt(b);
               c=parseInt(c);      

               var total=a+b+c;



               document.getElementById("total").value=total;


           }


       </script>


 </head>


 <body>
 <h1>QUALITY OF LABOR SURVEY</h1>
 <p />
 <h2>ABOUT YOUR COMPANY</h2>


 <div class="Wrapper">

     <form id="Main" method="post" action="Process.php">

         <div class="Question">
              1. In what state and county is your business located? (click below)
         </div>
         <div class='answer'>
         <?php
             $tsql = "select
                StateCountyID,
                State,
                County
                from dbo.StateCounty
                where State='MO'
                      and Active='True'
                order by State";

             $tsql2 = "select
                StateCountyID,
                State,
                County
                from dbo.StateCounty
                where State='IL'
                      and Active='True'
                order by State";


             /* Execute the query. */
             $stmt = sqlsrv_query( $conn, $tsql);
             if ( $stmt )
             {

                 echo "<span><select name='ListMO'>";
                 echo "<option value='0'>MO-County</option>";

                 while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC))
                 {

                     echo "<option value='".$row[0]."'>";
                     echo $row[2];
                     echo "</option>";

                 }

                 echo "</select></span>";

             }
             else
             {
                  echo "Error in statement execution.\n";
                  die( print_r( sqlsrv_errors(), true));
             }


             $stmt2 = sqlsrv_query( $conn, $tsql2);
             if ( $stmt2 )
             {

                 echo "<span><select name='ListIL'>";
                 echo "<option value='0'>IL-County</option>";

                 while( $row = sqlsrv_fetch_array( $stmt2, SQLSRV_FETCH_NUMERIC))
                 {
                     echo "<option value='".$row[0]."'>";
                     echo $row[2];
                     echo "</option>";

                 }

                 echo "</select></span>";

             }
             else
             {
                 echo "Error in statement execution.\n";
                 die( print_r( sqlsrv_errors(), true));
             }
        ?>
           </div>



         <table width="700px">
           <tr>
             <td style="font-size: 1.2em; font-weight: bold;">
                 ABOUT YOUR EMPLOYMENT
             </td>
             <td style="font-weight: bold;">
                 (Exclude Temporary Employees Throughout Survey)

             </td>
           </tr>

         </table>

         <p />
         <b>Please estimate the following:</b>







         <p />




         <div class="Question">
              4. Number of Full-Time Hourly Employees (Eligible for Full-Time Benefits)
         </div>

         <div class="Answer">
              <input type="text" id="a" value="0" onchange="Total();" />
         </div>

         <div class="Question">
              5. Number of Part-Time Hourly Employees(Not Eligible for Full-Time Benefits)
         </div>

         <div class="Answer">
              <input type="text" id="b" value="0" onchange="Total();" />
         </div>

         <div class="Question">
              6. Salaried Employees
         </div>

         <div class="Answer">
              <input type="text" id="c" value="0" onchange="Total();" />
         </div>





         <div class="Question">
              7. Is this your current number of employees?  If not, change responses to 4, 5, and 6.
         </div>

         <div class="Answer">
              <input type="text" id="total" value="0" onchange="Total();" />
         </div>

5 Cevap

var d=document.getElementById("d").value;

Eğer id="d" ile eleman var görünmüyor, çünkü hata üretir

Ben de senin gibi kod geliştirmek için bazı tavsiyelerde verecekti.

Debugging javascript

  • firefox eklentisi firebug kesinlikle javascript hata ayıklama için bir zorunluluktur.

https://addons.mozilla.org/en-US/firefox/addon/1843

Writting Javascript

  • Örneğin ayrı bir dosyada, javascript koyun: myjavascript.js ve html sayfa o dosyayı içerir. Bu sayfa ağırlığını azaltacak ve kod temiz ayrılık var olacaktır.
  • Eğer örnek jquery veya yui (Yahoo! User Interface Library), daha iyi javascript üretmek yardımcı olmak için javascript çerçeve kullanın.

http://jquery.com/
http://developer.yahoo.com/yui/

Writting PHP

  • Iyi ayrı dosyada PHP koyarak PHP / HTML ayrılması ve de onu. Örneğin:

http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html/

Kontrol etmek için bir kaç şey.

  • Tüm tarayıcılarda çalışmıyor mu?
  • Ne zaman tam kodu ayrı bir dosyada çalıştığını doğruladı
  • Eğer sayfanın altına senaryoyu taşımak için denediniz mi?

Ayrıca Firefox Debugger'ı kullanabilir hatta Firefox için Firebug gibi bir araç bulmak gerekir. Bu gibi konuları bulmada çok yardımcı olur.

Sorunuzu kısaltmak için deneyin! Onu izole!

Ben de son derece kullanarak tavsiye edebilir Firebug

Sen hiç zaman cevap bulacaksınız :)

Eğer HTML hiçbir eleman "d" var. Eğer satırı yorum ise:

var d=document.getElementById("d").value;

Bu ince çalışması gerekir