2

Im trying to implement the following logic on javascript.

If type is 'bankAccountTypeId' get all fields with the same className as field using $(field.className) then use .each to loop through each result compare field.value with $(this).val() and use alert to show an error message if they are different (break if fail).

function onChange_productListField(field, type) {

  if (HimmsJSUtil.elementHasClass(field, 'DC')) {

        var allProductGroupFields = $(".DC."+type);

        var value = field.value;

        if (field.options) {

              value = HimmsJSUtil.getSelectedDropDownOption(field);

        }

        allProductGroupFields.each(function(index) {

              if ($(this).attr("id") != field.id

                          && !$(this).val()) {

                    $(this).val(value);

              }

        });

  } else {



        /* implement the logic here */

  }

}

My question is , how would the type attribute work, within this logic?

Bobby Jack
  • 15,689
  • 15
  • 65
  • 97
mermaid
  • 25
  • 4
  • sorry but i can't understand nothing about your question as well as from your code! Can you explane what you are trying to do? and post html code, this will make things more faster. – Luca Filosofi Feb 26 '12 at 23:34

1 Answers1

0

Firsly let's make clear that jscript is not javascript and "type" in your code is not attribute but just a parameter of the function.

var allProductGroupFields = $(".DC."+type);

The above line uses jQuery to select a group of elements having classes "DC" and "bankAccountTypeId" at the same time where type is "bankAccountTypeId". Such a code can be used in a structure like this:

<div class="whatever">
    <input type="text" class="DC bankAccountTypeId" />
    <input type="text" class="DC userId" />
    <a href="http://stackoverflow.com/questions/1041344">
        jQuery multiple class selector
    <a>
</div>

Extra:
For a structure like this

<div class="DC">
    <input type="text" class="bankAccountTypeId" />
    <input type="text" class="userId" />
    <a href="http://stackoverflow.com/questions/3767512">
        jQuery class within class selector
    <a>
</div>

the selector line must be changed to

var allProductGroupFields = $(".DC ."+type);
sevenkul
  • 966
  • 1
  • 8
  • 14
  • Actually, that would produce the selector `".DC.bankAccountTypeId"` which would not select with the structure shown. For that structure you need to produce the selector `".DC .bankAccountTypeId"` or `".DC > .bankAccountTypeId"`. Or change the structure to have `
    `.
    – Blair McMillan Feb 26 '12 at 22:28
  • [This question](http://stackoverflow.com/questions/1041344/jquery-multiple-class-selector) says how to make intersection in selectors. There is no space for intersection. – sevenkul Feb 26 '12 at 22:32
  • That's correct. Which is why you would need to change the structure, or the selector. See http://jsfiddle.net/CmVPv/ for example – Blair McMillan Feb 26 '12 at 22:37