×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

@

give you an simple example.

本文发表在 rolia.net 枫下论坛<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Test</TITLE>
</HEAD>
<BODY>
<form name = "Test">
<TABLE>
<TR>
<TD>
<Select Name="Combo_1">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
</Select>
</TD>
</TR>
<TR>
<TD>
<Select Name="Combo_2">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
</Select>
</TD>
</TR>
<TR>
<TD>
<input type="Textbox" name="Result"></input>
</TD>
</TR>
<TR>
<TD>
<input type="Button" value="JavaScript" onClick="dowork_JavaScript();">
<input type="Button" value="vbScript" onClick="dowork_vbScript();">
</TD>
</TR>
</TABLE>
</form>
</BODY>
<script language="JavaScript">
function dowork_JavaScript()
{
var number1 = parseInt(document.Test.Combo_1.options[document.Test.Combo_1.selectedIndex].text);
var number2 = parseInt(document.Test.Combo_2.options[document.Test.Combo_2.selectedIndex].text);
document.Test.Result.value = number1 + number2
}
</script>
<script language="vbScript">
sub dowork_vbScript()
number1 = cint(document.Test.Combo_1.options(document.Test.Combo_1.selectedIndex).text)
number2 = cint(document.Test.Combo_2.options(document.Test.Combo_2.selectedIndex).text)
document.Test.Result.value = number1 + number2
end sub
</script>

</HTML>更多精彩文章及讨论,请光临枫下论坛 rolia.net
Report

Replies, comments and Discussions:

  • 工作学习 / IT杂谈 / 请教:FrontPage中表单内控件的计算问题
    用FrontPage做网页:插入一个表单,内含2个下拉框A和B,以及1个文本框C。要求文本框C中显示的值为2个下拉框A和B所选数值之和。

    如何用最简单的方法实现?

    用不着Java, CGI等牛刀,VBA就够了吧?(我找不到对下拉框A和B这2个对象的引用,以及计算求和后怎样对文本框C进行赋值,总之,对VBA不熟。)
    • javasript will do
    • It should be VB Script, not VBA. both Java Script and VB Script can do it, Java Script is better.
    • 谢以上各位
      • give you an simple example.
        本文发表在 rolia.net 枫下论坛<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
        <HTML>
        <HEAD>
        <TITLE>Test</TITLE>
        </HEAD>
        <BODY>
        <form name = "Test">
        <TABLE>
        <TR>
        <TD>
        <Select Name="Combo_1">
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
        <option>6</option>
        <option>7</option>
        </Select>
        </TD>
        </TR>
        <TR>
        <TD>
        <Select Name="Combo_2">
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
        <option>6</option>
        <option>7</option>
        </Select>
        </TD>
        </TR>
        <TR>
        <TD>
        <input type="Textbox" name="Result"></input>
        </TD>
        </TR>
        <TR>
        <TD>
        <input type="Button" value="JavaScript" onClick="dowork_JavaScript();">
        <input type="Button" value="vbScript" onClick="dowork_vbScript();">
        </TD>
        </TR>
        </TABLE>
        </form>
        </BODY>
        <script language="JavaScript">
        function dowork_JavaScript()
        {
        var number1 = parseInt(document.Test.Combo_1.options[document.Test.Combo_1.selectedIndex].text);
        var number2 = parseInt(document.Test.Combo_2.options[document.Test.Combo_2.selectedIndex].text);
        document.Test.Result.value = number1 + number2
        }
        </script>
        <script language="vbScript">
        sub dowork_vbScript()
        number1 = cint(document.Test.Combo_1.options(document.Test.Combo_1.selectedIndex).text)
        number2 = cint(document.Test.Combo_2.options(document.Test.Combo_2.selectedIndex).text)
        document.Test.Result.value = number1 + number2
        end sub
        </script>

        </HTML>更多精彩文章及讨论,请光临枫下论坛 rolia.net
        • 真是好人那!   另:有无某种工具可以使程序依次缩进、看起来有条理些?
          • try this
            • 再请教
              您给的例子是点击JavaScript或vbScript这2个button时用其onClick属性来产生计算。

              现在,我不需要这2个button,希望在下拉框中作出选择后,即调用JavaScript语句进行计算,不知下拉框有否类似onSelect这样的属性?(我试了onSelect,没反应)

              我怎样查到某个对象(如下拉框)还有什么其它什么属性?
              • use "onChange". the link is a HTML 4.0 Elements Reference from w3c.org