Auto-updating width/length/area using jQuery and Drupal6

社会主义新天地 提交于 2019-12-01 13:57:41

In your jQuery code, there should be parents used instead of parent for td lookup:

$parent = $(this).parents("td").children("div").children("div");

This makes area value to be calculated once width or length is changed.

EDIT:

There is also possible optimization of jQuery, for example to this (can be improved even more):

jQuery(document).ready( function ($) {
  $('input').change(function() {
    var $parent = $(this).parents("td").children("div").children("div"),
        length = $parent.find('input[id*="field-length-0-value"]').val(),
        width = $parent.find('input[id*="field-width-0-value"]').val();
    $parent.find('input[id*="field-area-0-value"]').val(length * width); 
  });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!