{"id":3165,"date":"2014-03-17T17:45:04","date_gmt":"2014-03-17T17:45:04","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/17\/calculate-form-fields-using-jquery-collection-of-common-programming-errors-2\/"},"modified":"2014-03-17T17:45:04","modified_gmt":"2014-03-17T17:45:04","slug":"calculate-form-fields-using-jquery-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/17\/calculate-form-fields-using-jquery-collection-of-common-programming-errors-2\/","title":{"rendered":"calculate form fields using jquery-Collection of common programming errors"},"content":{"rendered":"<p>You can bind a <code>change()<\/code> to both the <code>:radio<\/code> and elements to calculate the total.<\/p>\n<pre><code>$(\"select[name='number'], :radio[name='type']\").change(function(){\n    var $r = $(\":radio[name='type']:checked\");\n    var $d = $(\"select[name='number']\");\n    if($r.length ==1){\n        var t = parseInt($r.val(), 10);\n        var n = parseInt($d.val(), 10);\n        $(\"#result\").val(t*n);\n    }\n});\n<\/code><\/pre>\n<p><strong>Example on jsfiddle<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can bind a change() to both the :radio and elements to calculate the total. $(&#8220;select[name=&#8217;number&#8217;], :radio[name=&#8217;type&#8217;]&#8221;).change(function(){ var $r = $(&#8220;:radio[name=&#8217;type&#8217;]:checked&#8221;); var $d = $(&#8220;select[name=&#8217;number&#8217;]&#8221;); if($r.length ==1){ var t = parseInt($r.val(), 10); var n = parseInt($d.val(), 10); $(&#8220;#result&#8221;).val(t*n); } }); Example on jsfiddle<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3165","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3165"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3165\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}