如何从选择表单传递参数到URL?

时间:2016-07-25 14:07:51

标签: javascript php jquery html iframe

我想将值从选择表单传递到网址,以便使用iframe解决方案连接到外部网站。

我非常喜欢.PHP& JavaScript的。请帮帮我。

这是我创建的用于将用户数据传递到特定网址的表单。

/**
* 
* @author me
*
*/
class myClass{
    void thisMethod(){
        if(condition){

            /**
            * 
            * @author me
            * This is the local class
            */
            class localClass implements otherClass{

                /**
                * Method comment
                */              
                public boolean boolMethod(){
                    //Do Something
                }
            }
        }
    }
}

selectcourier.php

<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>

<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在我的网站上提供所有快递跟踪服务。但在这里,我无法区分不同类型的Courier服务的相应URL以传递值(cNum)并在iframe中打开该Web链接。

我拥有所有快递服务的所有网址。

现在,当用户选择Courier服务时,如何区分它们以获取适当的URL?

请帮助我。感谢。

1 个答案:

答案 0 :(得分:0)

由于您只是想根据选择将网址加载到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>