2011-12-31 69 views
0

有人可以解释我如何从两个下拉字段中捕获数据,并且当按下submit按钮时将这两个选择值连接在一起以创建一个随后被调用的URL。html表单捕获数据使url

例如。

下拉1:苹果 下拉2:橙

当您单击提交按钮会创建一个URL和负载:

http://www.fruittopick.com/apple-orange.html < - 它concats “苹果” & “ - ” & “橙色” &“.html”,然后加载该页面。

回答

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 
} 

希望它能帮助

+0

嘿接受任何答案,或评论,如果你仍然有任何问题,如果现在没有任何问题,然后通过接受答案投票答案 – Manoj 2011-12-31 14:17:51

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,它甚至会传递任何形式的信息。