在选择框中选择值 [英] Selecting values in a selection box

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

问题描述

我有一个表单,当它加载时我想突出显示在多选列表中选择的值(来自

a DB)(< select

multiple =" true">。

函数onLoad()

{

document.forms [0]。 elements [" multipleSelectList"]。value ="< value from

DB>" ;;

}


使用单个选择列表我知道您只需设置适当的值

但是无法通过多个选择找到如何执行此操作

列表。


非常感谢任何帮助。


BBB

解决方案

" booner"写于11/11/2003:

我有一个表单,当它加载时我想突出显示已被选中的
值(来自数据库)在多选列表中(< select
multiple =" true"> ;.

function onLoad()
{
document.forms [0] .elements [" multipleSelectList"]。value ="< value
from DB>" ;;
}

使用单个选择列表,我知道您只需设置适当的值
,但无法通过多个
选择列表找到如何执行此操作。

任何帮助将不胜感激。

BBB




使用''选项''数组:


multipleSelectElement.options [index] .selected = boolean;


Mike


-

Michael Winter

M.Winter @ [no-spam] blueyonder.co.uk(删除[无垃圾邮件]回复)


效果很好。


任何方式根据列表框中的内容选择选择列表中的选项?

BBB

Michael Winter < M.Winter @ [无垃圾邮件] blueyonder.co.uk>在消息中写道

新闻:E0 ****************** @ news-text.cableinet.net ...

奉承者写于2003年11月11日:

我有一个表单,当它加载时我想突出显示


值(来自

一个数据库)已在多选列表中选择(< select
multiple =" true">。

函数onLoad()
{<来自

DB>" ;;
}

使用单个选择列表我知道您只需设置值

但是无法找到如何执行此操作多个


选择

列表。

任何帮助将不胜感激。

BBB



使用''options''数组:

multipleSelectElement.options [index] .selected = boolean;

Mike

- -
Michael Winter
M.Winter @ [no-spam] blueyonder.co.uk(删除[no-spam]回复)



" booner"写于2003年11月11日:

这很有效。

任何方式根据
内容选择选择列表中的选项在列表框中?

BBB
Michael Winter < M.Winter @ [无垃圾邮件] blueyonder.co.uk>写在
消息新闻:E0 ****************** @ news-text.cableinet.net ...

" boner" ;写于2003年11月11日:

我有一个表单,当它加载时我想突出显示


值(来自

数据库
(< select multiple =" true">。

函数onLoad()
{
document.forms [0] .elements [" multipleSelectList"]。value =


"< value from

DB>" ;;
}

使用单个选择列表我知道您只需设置值

但是无法找到如何执行此操作多个


选择

列表。

任何帮助将不胜感激。

BBB



使用''options''数组:

multipleSelectElement.options [index] .selected = boolean;




没有理由不这样做。 ''options''属性只是一个Option

对象的数组:


Option.text:列表中显示的文字

Option.value:分配给该列表条目的值


你可能想要使用类似的东西:


var size = multipleSelectElement.options.length;


for(i = 0; i< size; ++ i)

{

//在这里测试列表选项的名称

if(multipleSelectElement.options [i] .text ==''something'')

{

//在这里选择

multipleSelectElement.options [i] .selected = true;

}

}


Mike


-

Michael Winter

M.Winter @ [no-spam ] blueyonder.co.uk(删除[无垃圾邮件]回复)


I have a form that when it loads I would like to highlight the values (from
a DB) that have been selected in a multiple selection list (<select
multiple="true">.

function onLoad()
{
document.forms[0].elements["multipleSelectList"].value = "<value from
DB>";
}

With a single selection list I know you simply set the value appropriately
however have not been able to find how to do this with multiple selection
lists.

Any help would be greatly appreciated.

BBB

解决方案

"booner" wrote on 11/11/2003:

I have a form that when it loads I would like to highlight the values (from a DB) that have been selected in a multiple selection list (<select
multiple="true">.

function onLoad()
{
document.forms[0].elements["multipleSelectList"].value = "<value from DB>";
}

With a single selection list I know you simply set the value appropriately however have not been able to find how to do this with multiple selection lists.

Any help would be greatly appreciated.

BBB



Use the ''options'' array:

multipleSelectElement.options[ index ].selected = boolean;

Mike

--
Michael Winter
M.Winter@[no-spam]blueyonder.co.uk (remove [no-spam] to reply)


That worked great.

Any way to select the choices in the selection list based on the content in
the listbox?

BBB
"Michael Winter" <M.Winter@[no-spam]blueyonder.co.uk> wrote in message
news:E0******************@news-text.cableinet.net...

"booner" wrote on 11/11/2003:

I have a form that when it loads I would like to highlight the


values (from

a DB) that have been selected in a multiple selection list (<select
multiple="true">.

function onLoad()
{
document.forms[0].elements["multipleSelectList"].value = "<value


from

DB>";
}

With a single selection list I know you simply set the value


appropriately

however have not been able to find how to do this with multiple


selection

lists.

Any help would be greatly appreciated.

BBB



Use the ''options'' array:

multipleSelectElement.options[ index ].selected = boolean;

Mike

--
Michael Winter
M.Winter@[no-spam]blueyonder.co.uk (remove [no-spam] to reply)



"booner" wrote on 11/11/2003:

That worked great.

Any way to select the choices in the selection list based on the content in the listbox?

BBB
"Michael Winter" <M.Winter@[no-spam]blueyonder.co.uk> wrote in message news:E0******************@news-text.cableinet.net...

"booner" wrote on 11/11/2003:

I have a form that when it loads I would like to highlight the


values (from

a DB) that have been selected in a multiple selection list (<select multiple="true">.

function onLoad()
{
document.forms[0].elements["multipleSelectList"].value =

"<value from

DB>";
}

With a single selection list I know you simply set the value


appropriately

however have not been able to find how to do this with multiple


selection

lists.

Any help would be greatly appreciated.

BBB



Use the ''options'' array:

multipleSelectElement.options[ index ].selected = boolean;



No reason why not. The ''options'' property is just an array of Option
objects:

Option.text: The text displayed in the list
Option.value: The value assigned to that list entry

You''d probably want to use something like:

var size = multipleSelectElement.options.length;

for( i = 0; i < size; ++i )
{
// Test the name of the list option here
if( multipleSelectElement.options[ i ].text == ''something'' )
{
// Select it here
multipleSelectElement.options[ i ].selected = true;
}
}

Mike

--
Michael Winter
M.Winter@[no-spam]blueyonder.co.uk (remove [no-spam] to reply)


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

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