0

我正在使用以下三个字段,需要multiply通过PHP. 任何帮助?代码为 - 1必须从这里select开始dropdown..

<select name="sp" id="sp">
<option value="" selected>Please Select...</option>
<option value="Editing">Editing</option>
<option value="Writing">Writing</option>
</select>

然后我有一个文本框,其中将提供数字,如单词 100 200 300,如

<input type="text" name="Word_Count" id="Word_Count" size="10">

第三个字段是代表上一行(100 200 300 字)计算价格的地方,如

<input type="text" name="price" id="price" value="" readonly="" size="20">

现在,如果用户将选择Editingfromselect框,价格将被计算为100 x 0.02, 200 x 0.02, 300 x 0.02like 而用户将选择Writing,价格将被计算为100 x 0.04, 200 x 0.04, 300 x 0.04

我怎样才能更有效地获得输出?有什么帮助吗?

4

2 回答 2

1

您将不得不处理许多复杂情况。
1) 检查 Word_Count 中输入的字符串是否为数字。(永远不要相信用户输入。应用验证技术)

2) 在 Word_Count 的 Onkeyup 事件上调用 javascript 函数。
<input type="text" name="Word_Count" id="Word_Count" size="10" onkeyup="return somefunction()">

我已经向你展示了如何通过在 element.xml 中提及函数来调用它。您还可以在页面加载时使用 bing jquery 功能。如果您愿意,最好查看官方文档。

html选择

<select name="sp" id="sp">
<option value="" selected>Please Select...</option>
<option value="0.02">Editing</option>
<option value="0.04">Writing</option>
</select>

更改了选项的值。


javascript/jquery 函数

function somefunction(){
    //take value of Word_Count in one variable
    var valWC = $("#Word_Count").val()

    //take value of Word_Count in one variable
    var valDP = $("#sp").val()

    //sumd will hold the product of two numbers
    var sumd = 0;

    //apply validation technique

    //multiply both values valWC and valDP
    //sumd will have the product
    sumd=Number(valWC)*Number(valDP);

    //show it in third box
    $("#price").val(sumd);
}
于 2013-01-04T07:22:11.823 回答
0

你可以在 Jquery 本身中做到这一点。你要做的是,

$("#sp").change(function() {

   // get the word count field  value;

   // split the values by using  " " character and store it into an array

   // loop the array [ inside the loop do your calculation according to the selection of the choice ]


   // display the final value in the price field..
});

有实现它的步骤。

于 2013-01-04T07:22:45.250 回答