2016-07-25 43 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