有人可以解释我如何从两个下拉字段中捕获数据,当按下提交按钮时,将这两个选择值连接在一起以创建一个随后被调用的URL。
例如
DropDown 1:Apple DropDown 2:橙色
当您点击提交按钮时,它会创建一个网址并加载:
http://www.fruittopick.com/apple-orange.html< - 它连续“苹果”& “ - ”& “橙色”& “.html”然后加载该页面。
答案 0 :(得分:2)
你可以创建一个在提交表单时调用的javascript函数, 例如见下文
function genURL()
{
var orange= document.getElementById('orangeCombo');
var apple= document.getElementById('appleCombo');
var finalURL="www.test.com"; // you can configure as per your need
finalURL= finalURL+orange+apple; // you can configure as per your need
window.location.href=finalURL; // to load generated URL
}
希望有所帮助
答案 1 :(得分:1)
如果你不介意一点点php:
<?php
$orange = $_POST['orange']; //replace orange with the name of dropdown 1.
$apple = $_POST['apple']; //replace apple with the name of dropdown 2.
$location = "www.example.com/".$orange."-".$apple.".html";
header('Location: '$location);
?>
将表单的操作设置为只包含上述代码的页面。 IIRC,它甚至会传递任何表格信息。