在下拉列表中选择选项

时间:2015-01-02 15:23:47

标签: javascript jquery html5 drop-down-menu

html

<table>
<tr>
<td>ENTER PRINCIPLE AMOUNT</td>
<td><input type="text" name="principle" size="7"></td>
</tr>

<tr>
<td>ENTER RATE OF INTEREST</td>
<td><input type="text" name="rate" size="7"></td>
</tr>
<tr>
<td>ENTER TIME</td> 
<td>
<SELECT id ="date" name = "dd"></SELECT>
            <SELECT id ="month" name = "mm"></SELECT>
            <SELECT id ="year" name = "yyyy"></SELECT>
</td>       
</tr>
</table>

js file

date_populate("date", "month", "year");  //to get dropdown list containing continuos values 
 i .e 1,2,3,4,5,6,7,8......31 in date to select number of days.in month 1,2,3...12.and
 in year 1,2,3....
 //as i move the cursor over dropdown menu i need to get this values.
 function simple()
{
var p,r,n,i;
if(document.interest.principle.val=="")
{
alert("pleas enter principle value");
document.interest.principle.alert();
}
else if(document.interest.rate.val=="")
{
alert("pleas enter rate value");
document.interest.rate.blur();
}
 else if(document.interest.year.val=="")
 {
 alert("pleas enter year value");
 document.interest.year.prompt();
 }
 else
 {
 p=parseInt(document.interest.principle.value);
  r=parseInt(document.interest.rate.value);
 n=parseInt(document.interest.year.value);
 i=p*r*n/100;
 document.interest.answer.value="simple interest:"+i;
 }
  }

我需要三个下拉菜单来选择日,月和年。当用户在下拉列表中选择这些值时,应该在简单兴趣文本字段中自动计算简单兴趣。但在上面的代码中,我只选择没有值的下拉列表。

1 个答案:

答案 0 :(得分:0)

请参阅小提琴:http://jsfiddle.net/Lyffxjx7/

$("select").on("change", function () {
    $("#amount").val(" " + $(this).val() + "s").show();
});

您必须使用多个输入重复此原则