有一个下拉框,其中可以包含 1-3 个出版物,具体取决于一个人订阅了哪些酒吧:
<?php foreach ($userCurrSubs as $pubChoice) { ?>
<option value="
<?php { echo $pubChoice->redirect_url ?>">
<?php echo $pubChoice->pub_name ?>
</option>
当用户选择所需的出版物时,他会被重定向到特定的 URL(上面代码中的redirect_url)。 redirect_url 代码如下所示:
while($row_Recordset2 = mysql_fetch_assoc($pubResultSet)){
$temppubItem = new PubItem();
$temppubItem->pub_name = $row_Recordset2['pub_name'];
$redirectURLtemp = $redirectURL . $temppubItem->pub_name. "/login/login?Read=";
$redirectURLtemp = $redirectURLtemp . urlencode($fromBasedURL . $temppubItem->pub_name );
$utcCurrentDate = gmdate ('Y-m-d');
$md5Temp = $loginUsername . $utcCurrentDate . 'none' . $Secret;
#error_log("string for md5=".$md5Temp);
$md5Temp = md5($md5Temp);
$redirectURLtemp = $redirectURLtemp . '&Id=' . $loginUsername . '&d=' . $utcCurrentDate . '&r=none' . '&c=' . $md5Temp;
$temppubItem->redirect_url = $redirectURLtemp;
error_log("list URL to choose.. ".$redirectURLtemp);
$userCurrSubs[] = $temppubItem;
};
我们将这些出版物称为:GunsAmmo、FieldStream 和 PsychologyToday。 (上面代码中的 pub_name)
GunsAmmo 和 FieldStream 工作正常。但是,当有人选择 PsychologyToday 时,他们需要被发送到完全不同的 URL,例如 http://www.psychologytoday.com ,且不附带任何上述登录业务。
(更好的是,最好不要让 PsychologyToday 出现在列表中,即使他们订阅了它,但我怀疑这将是一个更难解决的问题.)
实现这一目标的最佳方法是什么?我不是程序员,所以放轻松。
最佳答案
我有点困惑(尤其是你的第二个代码片段)。如果我正确理解您的问题,您应该在您的元素中使用 onChange 事件。
示例
<html>
<select onChange="document.location.href=this[selectedIndex].value">
<option value="www.example.com"> Option 1 </option>
</select>
</html>
关于PHP 下拉框根据选择重定向到不同的 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5318763/