2016-07-25 171 views
0

我想將選擇表格中的值傳遞到URL以便使用iframe解決方案連接到外部網站。如何將參數傳遞給選擇表單中的URL?

我很喜歡新的.PHP & JavaScript。請幫助我。

這是我創建的用於從用戶獲取數據傳遞到特定URL的表單。

<form action="selectcourier.php" method="GET"> 
<h1>Select courier service</h1> 

<select> 
<option value="Select">Select Courier Service</option> 
<option value="1">DTDC</option> 
<option value="2">AFL</option> 
<option value="3">BlueDart</option> 
</select> 

Consignment Number: <input type="text" name="cNum"><br> 

<center><input type="submit"></center> 
</form> 

selectcourier.php

<body> 
<form><center><h3><a href="http://dtdc.com/tracking/tracking_results.asp?action=track&sec=tr&ctlActiveVal=1&Ttype=awb_no&strCnno=H60874238&GES=N&TrkType2=awb_no&strCnno2=<?php echo $_GET["cNum"]; ?>" target="ifrm"> CONFIRM </a><h3></center> 

<iframe id="ifrm" width=300 height=300 seamless src="http://example.com/"> 
</body> 

我的問題:

希望你能明白,我想給所有快遞跟蹤服務從權我的網站使用iframe。但在這裏,我無法區分不同類型的快遞服務的適當URL以傳遞值(cNum)並在iframe中打開該鏈接。

我擁有所有快遞服務的所有網址。

現在,當用戶選擇快遞服務時,如何區分它們以選取合適的URL?

請幫助我。謝謝。

+0

所以基本上你希望用戶能夠選擇一個快遞跟蹤服務,然後該網站應該加載內部框架? – icecub

+0

在處理從「選擇」菜單中選擇的選項的iframe中有一些數據庫代碼 – RamRaider

+0

@icecub:感謝您的回覆。是的,我說得對。 – vIJAy

回答

0

既然你只是想根據選擇加載一個URL到一個iframe,我會去這個。基本解釋可以在評論中找到:

<html lang="en"> 
    <head> 
     <script type="text/javascript"> 
     // Set global variables 
     var serviceSelect; 
     var ConNumberElement; 

     // Wait for the page to be loaded 
     document.addEventListener('DOMContentLoaded', function() { 
      // Get required elements 
      serviceSelect = document.getElementById("CourierService"); 
      ConNumberElement = document.getElementById("cNum"); 
     }); 

     function loadWebsite(){ 
      // Get the iframe 
      var ifrm = document.getElementById("ifrm"); 

      // Get Consignment Number 
      var ConNumber = ConNumberElement.value; 

      // Get Courier Service 
      var serviceValue = serviceSelect.value; 

      // Make sure a correct service is selected 
      if(serviceValue == "1"){ // DTDC is selected 
       ifrm.src = "http://dtdc.com/tracking/tracking_results.asp?action=track&sec=tr&ctlActiveVal=1&Ttype=awb_no&strCnno=" + ConNumber + "&GES=N&TrkType2=awb_no&strCnno2=" + ConNumber; 
      } else if(serviceValue == "2"){ // AFL is selected 
       ifrm.src = ""; // Add the correct url here. Take the example above on how to do it. 
      } else if(serviceValue == "3"){ // BlueDart is selected 
       ifrm.src = ""; // Add the correct url here. Take the example above on how to do it. 
      } else { 
       alert("You have to select a correct Courier Service"); 
      } 
     } 
     </script> 
    </head> 
    <body> 
     <h1>Select courier service</h1> 

     <select id="CourierService"> 
      <option value="Select">Select Courier Service</option> 
      <option value="1">DTDC</option> 
      <option value="2">AFL</option> 
      <option value="3">BlueDart</option> 
     </select> 

     Consignment Number: <input type="text" id="cNum"><br> 

     <input type="button" onclick="loadWebsite();" value="CONFIRM" /> 

     <iframe id="ifrm" width=300 height=300 seamless src="http://example.com/"> 
    </body> 
</html> 
+0

網頁是不加載的IFRAME時,選擇一個快遞服務,並點擊提交。我怎樣才能使它工作? – vIJAy

+0

@vIJAy檢查您的控制檯。您嘗試在iframe內加載的網站可能不允許交叉框架。我自己測試了代碼,它工作正常,所以這是我能想到的唯一解釋。 – icecub

+0

同樣在與其他一些網站合作。 – vIJAy