2016-07-25 10 views
0

選択フォームの値をiframeソリューションを使用して外部のWebサイトに接続するためにURLに渡したいとします。選択フォームから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)を渡し、そのWebリンクをiframeで開くことができません。

私はすべての宅配便サービスのすべてのURLを持っています。

ユーザーが宅配サービスを選択したときに、適切なURLを取得するにはどうすればよいですか?

よろしくお願いします。ありがとう。

+0

基本的に、ユーザーは宅配便追跡サービスの1つを選択してから、そのウェブサイトをiframe内に読み込む必要がありますか? – icecub

+0

'select'メニューから選択したオプションを処理するiframeにデータベースコードがあります – RamRaider

+0

@icecub:あなたの返信をありがとう。はい、そうです。 – vIJAy

答えて

0

選択に基づいてiframeにURLをロードするだけでよいので、これを使用します。基本的な説明はコメントにあります:

<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

宅配便が選択され、送信時にクリックされると、Webページがiframeに読み込まれません。どのように私はそれを動作させることができますか? – vIJAy

+0

@vIJAyコンソールを確認してください。 iframeの内部で読み込もうとしているWebサイトが、原点を越えた​​枠組みを許可していない可能性があります。私は自分自身でコードをテストしました。それはうまく動作するので、私が考えることができる唯一の説明です。 – icecub

+0

同じものが他のいくつかのウェブサイトで動作しています。 – vIJAy

関連する問題