将下拉框中的值发送到另一个页面 [英] sending a value from drop down box to another page

查看:31
本文介绍了将下拉框中的值发送到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下下拉框.我希望能够从此框中选择一个值并使用 Php 将其发送到另一个页面.

这是我当前的 drop dwon box 代码:

版本2:

<div class="controls 控件-行"><选择名称="选择1" id="选择1"><option value="SelectIsland">选择您的岛屿</option><option value="stMaarten">St.马丁</option><option value="Aruba">Aruba</option><option value="Curacou">Curacou</option><option value="StBarths">St.Barths</option></选择><选择名称=选择2"><option value="SelectLoc">选择您的位置</option><option value="Philipsburg">Philipsburg</option><option value="SimpsonBay">Simpson Bay</option><option value="Maho">Maho</option><option value="Cupecoy">Cupecoy</option><option value="Middleregion">Middle region</option><option value="MadameEstate">Madame Estate</option><option value="StPeters">St.彼得斯</option><option value="DawnBeach">黎明海滩</option></选择><input type="submit" name="button" class="btn btn-primary" value="Find Restaurant" style="margin-top:-10px; margin-right:0px"/>

<?php$select1 = $_POST['select1'];?></表单>

我试图通过 $select1 到 search.php,使用这个: $select1 = $_POST['select1'];

但是我得到了以下错误,没有做任何事情:注意:未定义索引:select1 in C:\wamp\www\iLandgrub.com V 1.2\main page\index.php on line 194, on y index.php.

如果我删除 $select1 = $_POST['select1'];然后它会起作用,但在 search.php 上我没有得到我想要的值.

这是我在 search.php 中的代码:

这同样适用于 select2.我已经在我的 index.php 中没有做任何事情我得到错误未定义的索引.

这是 index.php 中的错误,当您转到此页面时.

解决方案

那是因为您正在使用锚元素.改变

<a href="search.php" class="btn btn-primary" style="margin-top:-10px; margin-right:0px"type="button" name="button">寻找餐厅</a>

这会将表单数据发布到 search.php - 如果您希望页面提交给自身,请将 action="search.php" 更改为 action="".

注意:您需要更改 CSS 以相同方式设置按钮样式.

I have the following drop down box. I want to be able to select a value from this box and using Php sending it to another page.

this is my current code for drop dwon box:

version2:

<form style="margin-top:20px; margin-right:+50px" name="formname" method="post" action="search.php">
<div class="controls controls-row">
<select name="select1" id="select1"> 
<option value="SelectIsland">Select your island</option>
<option value="stMaarten">St. Maarten</option>
<option value="Aruba">Aruba</option>
<option value="Curacou">Curacou</option>
<option value="StBarths">St. Barths</option>
</select>   

<select name="select2"> 
<option value="SelectLoc">Select your location</option>
<option value="Philipsburg">Philipsburg</option>
<option value="SimpsonBay">Simpson Bay</option>
<option value="Maho">Maho</option>
<option value="Cupecoy">Cupecoy</option>
<option value="Middleregion">Middle region</option>
<option value="MadameEstate">Madame Estate</option>
<option value="StPeters">St. Peters</option>
<option value="DawnBeach">Dawn Beach</option>
</select>
<input type="submit" name="button" class="btn btn-primary" value="Find Restaurant" style="margin-top:-10px; margin-right:0px" />
</div>
<?php 
$select1 = $_POST['select1'];
?>
</form>

I am trying to pass $select1 to search.php, using this: $select1 = $_POST['select1'];

however I get this following error, without doing anything: Notice: Undefined index: select1 in C:\wamp\www\iLandgrub.com V 1.2\main page\index.php on line 194, on y index.php.

If I remove $select1 = $_POST['select1']; then it will work but on search.php I dont get the values I wanted.

this my code in search.php:

the same applies for select2, as well. I am already in my index.php withut doing anything I get the error Undefined index.

<?php
if(isset($_POST['select1']) && isset($_POST['select2'])) {
$select1 = $_GET['select1'];
$select2 = $_GET['select2'];
echo $select1;
echo "";
echo $select2;
}
else{
echo "not set";
}
?> 

this is the error in index.php, when you go to this page.

解决方案

That's because you're using an anchor element. Change

<a href="search.php" class="btn btn-primary" style="margin-top:-10px; margin-right:0px"type="button" name="button">Find Restaurant</a>

to

<input type="submit" class="btn btn-primary" value="Find Restaurant" />

This will post the form data to search.php - if you want the page to submit to itself, change action="search.php" to action="".

Note: you will need to change your CSS to style the button in the same way.

这篇关于将下拉框中的值发送到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆