Javascript operator ^=

I cannot find any references to what the expression ^= means.  I'm trying to understand the following code:

function amountOrPercentage(fieldGroup){
                  var counter=0;
                  $("input[fieldGroup^='"+ fieldGroup + "']").each(function() {
                      if ($(this).val().length) counter ++;
                      if (counter>1) {
                              _message("Error", "You can only enter a dollar amount or percentage, not both");
                              $(this).val('');
                              $(this).focus();
                              return
                      }
                  });
          }
Cy2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
This is a jQuery starts with selector.

http://api.jquery.com/attribute-starts-with-selector/

In your case it means find all input elements with an attribute fieldGroup that starts with whatever is contained in the fieldGroup variable.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
Breaking the code down

function amountOrPercentage(fieldGroup){
  var counter=0;
  // FIND ALL input ELEMENTS WITH ATTRIBUTE fieldGroup
  // EQUAL TO PARAMETER fieldGroup AND FOR EACH DO ....
  $("input[fieldGroup^='"+ fieldGroup + "']").each(function() {
    // CHECK IF THE INPUT HAS A VALUE AND INCREASE
    // COUNTER IF IT DOES
    if ($(this).val().length) counter ++;
    
    // CHECK FOR MORE THAN ONE input WITH A VALUE
    // IF COUNTER IS > 1 THEN WE HAVE MORE THAN 1 
    // INPUT WITH A VALUE - SO DISPLAY ERROR
    // CLEAR input FOCUS IT AND EXIT
    if (counter>1) {
      _message("Error", "You can only enter a dollar amount or percentage, not both");
      $(this).val('');
      $(this).focus();
      return
    }
  });
} 

Open in new window

The code is basically checking all inputs within a particular grouping (defined by the attribute fieldGroup) that only 1 input has a value.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.