0

嗨!我是网络开发的新手,只是停留在一个点上。我有一个表单,其中一个下拉菜单生成 2 个字段。现在的问题是我已经生成了一个字段并试图获得另一个字段但由于缺乏知识我被卡住了。如果有人可以,我只需要一点帮助

<form name="myform">
    <select name="optone" size="1" onchange="setOptions(document.myform.optone.options[document.myform.optone.selectedIndex].value);">
        <option value=" " selected="selected"> </option>
        <option value="1">Directory Submission</option>
        <option value="2">Articale Submission</option>
        <option value="3">Social Bookmarking</option>
        <option value="4">Blog Commenting</option>
        <option value="5">Forum Submission</option>
        <option value="6">Link Building</option>
    </select>
    No. Of Submissions: <select name="opttwo" size="1">
        <option value=" " selected="selected">Select any option of the above first</option>
    </select>
    Amount Payable:
</td>
<td>
    <input type="text" name="amount" onchange="document.myform.opttwo.options[document.myform.opttwo.selectedIndex].value;" />

现在我的javascript是这样的:

function setOptions(chosen) {
    var selbox = document.myform.opttwo;
    selbox.options.length = 0;
    if (chosen == " ") {
        selbox.options[selbox.options.length] = new Option('Please select one of the options above first',' ');
    }
    if (chosen == "1") {
        selbox.options[selbox.options.length] = new Option('100 Directory Submission', '$9.99');
        selbox.options[selbox.options.length] = new Option('100 Directory Submission', '$9.99');
        selbox.options[selbox.options.length] = new Option('300 Directory Submission','$29.99');
    }

    // and like this other options will come too.
}

我只想知道应付金额字段如何获得金额。

4

1 回答 1

0

你的意思是

演示

function setOptions(chosen) {
    var selbox = document.myform.opttwo;
    selbox.options.length = 1; // no need to delete the first option
    if (chosen == "1") {
        selbox.options[selbox.options.length] = new Option('100 Directory Submission', '$9.99');
        selbox.options[selbox.options.length] = new Option('100 Directory Submission', '$9.99');
        selbox.options[selbox.options.length] = new Option('300 Directory Submission','$29.99');
    }
    document.myform.amount.value="";
    // and like this other options will come too.
}​

使用此代码

      <select name="opttwo" size="1" onchange="this.form.amount.value=this.value;">
        <option value=" " selected="selected">Select any option of the above first</option>
      </select>
      Amount Payable:
   </td>
   <td>
     <input type="text" name="amount" readonly="readonly" />
于 2012-12-04T12:32:27.370 回答