繁体   English   中英

如何通过选择表单将参数传递给URL?

[英]How to pass parameters to a URL from a select form?

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

我非常了解.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从我的网站直接提供所有快递跟踪服务 但是在这里,我无法区分不同类型的Courier Service的适当URL,以传递值(cNum)并在iframe中打开该Web链接。

我拥有所有快递服务的所有URL。

现在,当用户选择快递服务时,如何区分他们以选择适当的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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM