2017-06-30 37 views
-1

如何從外部js文件顯示這個特定的下拉菜單(國家和地區)?在帶有select和option標籤的常規HTML表單中,它完美地工作,但是當使用php時它不會.js文件位於我正在使用的某個文件夾中,並且它在正常的html文件中正常工作。用PHP它不會運行。不知怎的,它似乎無法調用PHP內部的.js文件與選擇和選項如何顯示從PHP的外部js文件的Dropbox?

<!DOCTYPE html> 
    <html> 
    <head> 
     <title></title> 
     <style> 
     </style> 
     <body> 
     <form action="" method="POST"> 
     Select Country (with states): 
     <select id="country" name="country" required></select> 
     <br>State: 
     <select name="region" id="region" required></select> 
     <br> 
     <input type="submit" name="submit" value="Registros"> 

     <script src="locations.js"></script> 
     <script src="locations2.js" language="javascript"></script> 
     </form> 

     </head> 

     <?php 

     if(isset($_POST['submit'])){ 

     echo "<tr><form action='' method='POST'>"; 
     echo "<td><select name='technology'><option>ERP/CRM/EPM/BI</option><option>Cyber Security</option><option>Networking</option><option>Infrastructure</option><option>Big Data/M2M/IoT/Blockchain</option><option>Physical Security</option></select></td>"; 
     echo "<td><select name='description'><option>VENDOR</option><option>VAD</option><option>VAR</option><option>CUSTOMER</option></td>"; 

     echo "<td><select id='country' name='country'><option><script src='locations.js'></script></option></select></td>"; 
     echo "<td><select id='region' name='region'><option><script src='locations2.js'></script></option></select></td>"; 
     echo"</form></tr>";   

     } 

     ?> 

     </body> 
     </html> 
+0

這看起來很奇怪。你能澄清這應該如何工作?請包括引用的'js'文件。 – ventiseis

+0

其實我正在到達一個mysqli數據庫(MAMP),它使我回到之前註冊的選定選項,並且應該打開此下拉菜單以便可以更新狀態。例如,我應該能夠選擇另一個國家並說明並更新此表格。這個js文件是一個包含世界上所有國家和州的大文件。這是一個連接的下拉列表,即首先選擇國家,然後在此特定國家選擇州。對於'技術'和'描述',由於選項標籤是本地的,因此選擇一切正常。 Tks爲您提供幫助。 – Marcelo

回答

0

而不是2 JavaScript中,可以使用國家地區庫來緩解你的發展。檢查這個免費的圖書館:https://github.com/geodatasource/country-region-dropdown-menu。託管的圖書館可用,你不需要本地,如果你想。

<html> 
    <head> 
    <meta charset="UTF-8"> 
    <script src="//cdnjs.cloudflare.com/ajax/libs/country-region-dropdown-menu/1.1.0/geodatasource-cr.min.js"></script> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> 
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> 
    <link rel="stylesheet" href="dist/geodatasource-countryflag.css"> 
    </head> 
    <body> 

    <div> 
     Country: <select class="gds-cr" country-data-region-id="gds-cr-one" ></select> 

     Region: <select id="gds-cr-one" ></select> 
    </div> 

    </body> 
</html> 
+0

克里斯。 – Marcelo