从下拉框传递值 [英] Pass on values from drop-down box

查看:59
本文介绍了从下拉框传递值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想知道是否有人可以给我一些提示我要做什么来获得

这个工作:我正在创建一个下拉框使用下面的脚本。


结果是两个文本字段;现在我想将这些值从下拉框传递到下一页。接下来的页面应该是

看起来像这样:

月:

年份:

值应该是来自下拉框中的那些...

我一直在瞎盯着如何实现这一目标。

如果有人可以拥有,那将是非常感激的看看......这是

到目前为止我得到的:

< script language =" JavaScript"><! -

函数setForm2Value(){

var selectedItem = document.formName1.selectName1.selectedIndex;

var selectedItemValue =

document.formName1。 selectName1.options [selectedItem] .value;

var selectedItemText =

document.formName1.selectName1.options [selectedItem] .text;

if (selectedItem!= 0){

document.formName2.textboxName1.value = selectedItemText;

document.formName2.textboxName2.value = selectedItemValue;

}

else {

document.formName2.textboxName1.value = " ;;

document.formName2.textboxName2.value ="" ;;


}

}

// - >< / script>

事件级别< br>

< form name =" formName1">

< select name =" selectName1" onChange =" setForm2Value()">

< option>进行选择:

< option value =" 2000"> January

< option value =" 2001">二月

< option value =" 2002">三月

< / select>

< / form>


< p>

< form name =" formName2"方法= QUOT; POST" action =" step2.htm">

< input type =" text"名称= QUOT; textboxName1"值= QUOT;"大小= QUOT; 20">欧元

< input type =" text"名称= QUOT; textboxName2"值= QUOT;" size =" 6">

< input type =" submit" VALUE ="下一步] class = button>

< / FORM>

这会创建下拉列表,当做出选择时,会有两个

文本框底部是填充的。当我点击下一步按钮时,

将我带到新页面。到现在为止还挺好。问题是:怎么做

我从这两个文本框中获取值到

新页面上的两个新文本字段?过去两天我一直在盯着这个,并尝试了一下我可以在示例代码中找到的所有内容,但我必须做的事情

出错了,因为这些值不会出现在新页面上。可以

任何人都提供了一些提示,或者更好的是,还有一些示例代码?

提前感谢一大堆!

Naz

Hello all,
I wonder if anybody can give me a hint about what I have to do to get
this working: I am creating a drop down box using the script below. The

result is two text fields; now I want to pass those values, which come
from the drop down box, to the next page. The next page should then
simply look like this:
Month:
Year:
And the values should be the ones from the drop-down box...
I have been staring myself blind about how to get this accomplished.
Would be more than grateful if somebody could have a look...here is
what I got so far:
<script language="JavaScript"><!--
function setForm2Value() {
var selectedItem = document.formName1.selectName1.selectedIndex;
var selectedItemValue =
document.formName1.selectName1.options[selectedItem].value;
var selectedItemText =
document.formName1.selectName1.options[selectedItem].text;
if (selectedItem != 0) {
document.formName2.textboxName1.value = selectedItemText;
document.formName2.textboxName2.value = selectedItemValue;
}
else {
document.formName2.textboxName1.value = "";
document.formName2.textboxName2.value = "";

}
}
//--></script>
Incident Level <br>
<form name="formName1">
<select name="selectName1" onChange="setForm2Value()">
<option>Make A Selection:
<option value="2000">January
<option value="2001">February
<option value="2002">March
</select>
</form>

<p>
<form name="formName2" method="POST" action="step2.htm">
<input type="text" name="textboxName1" value="" size="20"> Euro
<input type="text" name="textboxName2" value="" size="6">
<input type="submit" VALUE="Next" class=button>
</FORM>
This creates the drop down list, and when a selection is made, two
textboxes at the bottom are filled. When I hit the ′Next′ button,
that takes me to the new page. So far, so good. The problem is: how do
I get the values from those two textboxes to two new text fields on the

new page ? I have been staring at this for the last two days, and tried

about everything I could find in sample codes, but I must be doing
something wrong, because the values do not appear on the new page. Can
anybody provide me with a hint, or better yet, some sample code ?
Thanks a bunch in advance !
Naz

推荐答案

" nazgulero" < GE ********** @ wanadoo.nl>在消息中写道

news:11 ********************** @ g49g2000cwa.googlegr oups.com ...
"nazgulero" <ge**********@wanadoo.nl> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
大家好,

我想知道是否有人可以给我一些暗示我必须做什么才能使
这个工作:我正在使用下面的脚本创建一个下拉框。

结果是两个文本字段;现在我想将这些值从下拉框传递到下一页。接下来的页面应该如下所示:

< snipped />
< form name =" formName2"方法= QUOT; POST" action =" step2.htm">
< input type =" text"名称= QUOT; textboxName1"值= QUOT;"大小= QUOT; 20">欧元
< input type =" text"名称= QUOT; textboxName2"值= QUOT;" size =" 6">
< input type =" submit" VALUE ="下一步] class = button>
< / FORM>

这会创建下拉列表,当进行选择时,底部会填充两个
文本框。当我点击下一步按钮时,
会将我带到新页面。到现在为止还挺好。问题是:如何在
新页面上获取这两个文本框中的值到两个新文本字段?过去两天我一直盯着这个,试过
Hello all,
I wonder if anybody can give me a hint about what I have to do to get
this working: I am creating a drop down box using the script below. The

result is two text fields; now I want to pass those values, which come
from the drop down box, to the next page. The next page should then
simply look like this:
<snipped />
<form name="formName2" method="POST" action="step2.htm">
<input type="text" name="textboxName1" value="" size="20"> Euro
<input type="text" name="textboxName2" value="" size="6">
<input type="submit" VALUE="Next" class=button>
</FORM>

This creates the drop down list, and when a selection is made, two
textboxes at the bottom are filled. When I hit the ′Next′ button,
that takes me to the new page. So far, so good. The problem is: how do
I get the values from those two textboxes to two new text fields on the
new page ? I have been staring at this for the last two days, and tried




你需要服务器端代码才能做到这一点......


你把两个文本框发布到下一页,所以到目前为止一切都很好。

但下一页是.htm文件(step2.htm,无法运行

用于提取您发布的数据的服务器端脚本。


作为示例(在服务器上使用ASP):


*用step2.asp替换step2.htm,并将其放在.asp文件中:

<%@ LANGUAGE =" VBSCRIPT"%>

<%

Dim monthValue

monthValue = Request.Form(" textboxName1")

Dim yearValue

yearValue = Request.Form(" textboxName2")

%>


<!DOCTYPE html PUBLIC" - / / W3C // DTD XHTML 1.0 Transitional // EN"

" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

< html xmlns =" h ttp://www.w3.org/1999/xhtml">

< head>

< meta http-equiv =" Content-Type"含量=" text / html的;字符集= ISO-8859-1" />

< title>页面标题< / title>

< / head>


< body>

< p>月:<%= monthValue%>< / p>

< p>年:<%= yearValue%>< ; / p>

< / body>

< / html>


-

Dag。



You need server-side code to do that...

You post your two textboxes to the next page, so all is well so far.
But the next page is a .htm file (step2.htm", with no ability to run
serverside script to extract the data you posted.

As an example (using ASP on the server):

* Replace "step2.htm" with step2.asp, and put this in the .asp file:
<%@LANGUAGE="VBSCRIPT"%>
<%
Dim monthValue
monthValue = Request.Form("textboxName1")

Dim yearValue
yearValue = Request.Form("textboxName2")
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Page Title</title>
</head>

<body>
<p>Month: <%=monthValue%></p>
<p>Year: <%=yearValue%></p>
</body>
</html>

--
Dag.




你好Dag,


很棒,感谢您的快速帮助。我会尝试一下让你知道




问候,


Naz

***通过开发人员指南 http://www.developersdex.com 发送***

Hello Dag,

great, thanks for your quick help. I′ll give that a try and let you know
!

Regards,

Naz
*** Sent via Developersdex http://www.developersdex.com ***


nazgulero写道:
nazgulero wrote:
大家好,

我想知道是否有人可以给我一个提示我需要做些什么来使这个工作:我正在使用下面的脚本创建一个下拉框。
Hello all,
I wonder if anybody can give me a hint about what I have to do to get
this working: I am creating a drop down box using the script below. The



以下示例可能有所帮助:


<! - Page 1 HTML: - >


< html>

< title>播放< / title>


< form action =" page2.html" >

< select name =" month">

< option> January< / option>

< option>二月< /选项>

<选项>三月< /选项>

< / select>

< select name ="年份>

<选项> 2005< /选项>

<选项> 2006< / option>

< option> 2007< / option>

< / select>

< input type =" submit">

< form>

< / html>

<! - Page 2 HTML: - >


< html> < title>第2页< / title>

< script type =" text / javascript">

function getMonthYear(){

var s = window.location.search.replace(/ ^ \?/,'''')。split(''&'');

for(var i = 0 ,len = s.length; i< len; ++ i){

var x = s [i] .split(''='');

文件.getElementById(x [0])。innerHTML = x [1];

}

}

< / script>

< body onload =" getMonthYear();">


< span id =" month">< / span>& nbsp;< span id =" year">< / span>

< / body>< / html>


-

Rob


The following example may help:

<!-- Page 1 HTML: -->

<html>
<title>Play</title>

<form action="page2.html">
<select name="month">
<option>January</option>
<option>February</option>
<option>March</option>
</select>
<select name="year">
<option>2005</option>
<option>2006</option>
<option>2007</option>
</select>
<input type="submit">
<form>
</html>
<!-- Page 2 HTML: -->

<html> <title>page 2</title>
<script type="text/javascript">
function getMonthYear(){
var s = window.location.search.replace(/^\?/,'''').split(''&'');
for (var i=0, len=s.length; i<len; ++i){
var x = s[i].split(''='');
document.getElementById(x[0]).innerHTML = x[1];
}
}
</script>
<body onload="getMonthYear();">

<span id="month"></span>&nbsp;<span id="year"></span>
</body></html>

--
Rob


这篇关于从下拉框传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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