首页 \ 问答 \ jQuery-动态地将具有不同id的表行的输入值相乘(jQuery- Dynamically multiply input values of table rows with different id)

jQuery-动态地将具有不同id的表行的输入值相乘(jQuery- Dynamically multiply input values of table rows with different id)

使用下面的代码动态添加表行。 输入ID附加用户ID。

var selResId = jQuery('#grid').jqGrid('getGridParam', 'selarrrow');

    var j=1;
    for (var i=0, il=selResId.length; i < il; i++) {
        var name = jQuery('#grid').jqGrid('getCell', selResId[i], 'USER_NAME');

    $('#addr'+j).html("<td style='text-align:center;'>"+name+"</td><td><input id='hours_"+selResId[i]+"' value='80' type='text' readonly  /></td><td><input id='rate_"+selResId[i]+"' type='text' /></td><td><input name='markup_"+selResId[i]+"' type='text'/></td><td><input name='totalcost_"+selResId[i]+"' type='text' readonly></td>");
    $('#resource_table').append('<tr id="addr'+(j+1)+'"></tr>');
        j++;
        }
    }

HTML生成

<tr id="addr1">
    <td>John Doe</td>
    <td><input type="text" readonly="" value="80" id="hours_10"></td>
    <td><input type="text" value="" id="rate_10"></td>
    <td><input type="text" value="" id="markup_10"></td>
    <td><input type="text" readonly="" value="" id="totalcost_10"></td>
</tr>

<tr id="addr2">
    <td>Foo User</td>
    <td><input type="text" readonly="" value="80" id="hours_11"></td>
    <td><input type="text" value="" id="rate_11"></td>
    <td><input type="text" value="" id="markup_11"></td>
    <td><input type="text" readonly="" value="" id="totalcost_11"></td>
</tr>

如何将hours, rate and markup输入值相乘hours, rate and markup使用以下公式在总成本输入下显示。 该活动可能是关键。

Initially, totalcost = hours * rate

Case 1: If markup (%) > 0, for eg: 10%, then markup_cost = (hours * rate * markup) / 100
totalcost = (hours * rate) + markup_cost

Case 2: If markup (%) < 0, for eg: -10%, then markup_cost = (hours * rate * markup) / 100
totalcost = (hours * rate) - markup_cost

Dynamically adding table rows using below code. User ID is appended for input id.

var selResId = jQuery('#grid').jqGrid('getGridParam', 'selarrrow');

    var j=1;
    for (var i=0, il=selResId.length; i < il; i++) {
        var name = jQuery('#grid').jqGrid('getCell', selResId[i], 'USER_NAME');

    $('#addr'+j).html("<td style='text-align:center;'>"+name+"</td><td><input id='hours_"+selResId[i]+"' value='80' type='text' readonly  /></td><td><input id='rate_"+selResId[i]+"' type='text' /></td><td><input name='markup_"+selResId[i]+"' type='text'/></td><td><input name='totalcost_"+selResId[i]+"' type='text' readonly></td>");
    $('#resource_table').append('<tr id="addr'+(j+1)+'"></tr>');
        j++;
        }
    }

HTML Generated

<tr id="addr1">
    <td>John Doe</td>
    <td><input type="text" readonly="" value="80" id="hours_10"></td>
    <td><input type="text" value="" id="rate_10"></td>
    <td><input type="text" value="" id="markup_10"></td>
    <td><input type="text" readonly="" value="" id="totalcost_10"></td>
</tr>

<tr id="addr2">
    <td>Foo User</td>
    <td><input type="text" readonly="" value="80" id="hours_11"></td>
    <td><input type="text" value="" id="rate_11"></td>
    <td><input type="text" value="" id="markup_11"></td>
    <td><input type="text" readonly="" value="" id="totalcost_11"></td>
</tr>

How do I multiply input values for hours, rate and markup and show it under total cost input using below formula. The event could be keyup.

Initially, totalcost = hours * rate

Case 1: If markup (%) > 0, for eg: 10%, then markup_cost = (hours * rate * markup) / 100
totalcost = (hours * rate) + markup_cost

Case 2: If markup (%) < 0, for eg: -10%, then markup_cost = (hours * rate * markup) / 100
totalcost = (hours * rate) - markup_cost

原文:https://stackoverflow.com/questions/32064574
更新时间:2021-08-04 14:08

最满意答案

mysql_real_escape_string()需要一个db连接。 尝试这个 ....

<?php
$un = $_POST["u"];
$pk = $_POST["p"];
$ok = $_POST["o"];

$link = mysql_connect('localhost', 'root', 'randompassword');
if (!$link){
  die(' Oops. We Have A Problem Here: ' . mysql_error());
}

if ($link){
  echo 'connected succesfully';
}

mysql_select_db("forum") or die(' Oops. We Have A Problem Here: ' . mysql_error());

$u = mysql_real_escape_string($un);
$p = mysql_real_escape_string($pk);
$o = mysql_real_escape_string($ok);
$sql = "INSERT INTO users (username, password, occupation) VALUES ('$u', '$p', '$o')";
$ins_sql = mysql_query($sql);
IF($ins_sql) {
  echo 'Inserted new record.';
}ELSE{
  echo 'Insert Failed.';
}
?>

mysql_real_escape_string() requires a db connection. Try this ....

<?php
$un = $_POST["u"];
$pk = $_POST["p"];
$ok = $_POST["o"];

$link = mysql_connect('localhost', 'root', 'randompassword');
if (!$link){
  die(' Oops. We Have A Problem Here: ' . mysql_error());
}

if ($link){
  echo 'connected succesfully';
}

mysql_select_db("forum") or die(' Oops. We Have A Problem Here: ' . mysql_error());

$u = mysql_real_escape_string($un);
$p = mysql_real_escape_string($pk);
$o = mysql_real_escape_string($ok);
$sql = "INSERT INTO users (username, password, occupation) VALUES ('$u', '$p', '$o')";
$ins_sql = mysql_query($sql);
IF($ins_sql) {
  echo 'Inserted new record.';
}ELSE{
  echo 'Insert Failed.';
}
?>

相关问答

更多
  • 不确定您的数据集是如何设置的......但您可以执行条件订单 ORDER BY CASE WHEN postalcode < your_code THEN 1 WHEN postalcode = your_code THEN 2 WHEN postalcode > your_code THEN 3 ELSE 4 END 逻辑将很可能需要改变,但这是一般的想法..其中1是2之前,这是3 ..你可以改变它模具,但你需要它..但没有数据和表模 ...
  • 用$website检查一行。 你最后有一个额外的括号(或者,另一端可能缺少mysql_real_escape调用)。 要在将来检查此类语法错误, php -l myfile.php在命令行上运行php -l myfile.php 。 或者,在开发和测试过程中,确保正确配置了error_reporting和display_errors ,以便这些语法错误显示在脚本的输出中。 Check the line with $website. You have an extra parenthesis on the e ...
  • 你的方法只能工作一年; 否则,如果您不希望将多年的月份组合在一起,则需要其他列。 您还应该使用date函数而不是检查整数值(您不应该将日期存储为int)。 如果需要动态方法,则需要在PHP端进行动态查询准备(获取开始/结束日期并生成SQL)。 这可能是您正在寻找的解决方案:
  • 尝试SELECT MAX(timestamp) FROM entry_list WHERE username = 'user' 也可能不是最好的想法使用保留关键字作为列名,尝试将timestamp更改为insert_date或类似的东西 Try SELECT MAX(timestamp) FROM entry_list WHERE username = 'user' also, probably not the best idea to use reserved keywords as column nam ...
  • 停止使用mysql_* 开始使用像PDO这样的东西,这是MySQL开发人员的一个很好的教程 。 您应该尽快更改,因为您的代码是对SQL注入开放的。 在一个简单的表单中,您的一些表名称: $stmt = $db->prepare( "SELECT FROM tbltestassignment WHERE TeacherId=?" ); $stmt->execute(array( $_SESSION["UserId"]), ); $rows = $stmt->fetch( \PDO::FETCH_ASS ...
  • $sql=" SELECT * FROM ART where 1=1 "; if(!empty($category) { $sql.=" and category= $value"; } if(!empty($subject) { $sql.=" and subject= $value"; } if(!empty($medium) { $sql.=" and medium= $value"; } 其中1 = 1只是为了保持语法正确,否则你需要有一些登录来相应地添加,因为你不能在 ...
  • mysql_real_escape_string()需要一个db连接。 尝试这个 ....
  • 这是我最近工作的一个简单示例,我需要循环访问多个复选框并将这些值传递给SQL语句。 虽然这个例子发生在点击按钮上,但希望它与你想要完成的事情有关,或者至少在开始时...... :)
  • 您需要更改$sql变量以删除单引号上的转义。 它们作为字符串的一部分注册,因为您使用双引号来包装它。 基本上,您告诉数据库运行查询“ SELECT * FROM NAME WHERE FIRST_NAME = \'John\' and LAST_NAME = \'Smith\' and MEMBERSHIP_NUMBER = \'VRX78435\' ”。 如果直接运行它会出错,因为转义字符不会转义。 $sql = "SELECT * FROM NAME WHERE FIRST_NAME = '$first ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)