Error referencing id containing $

Home Forums General discussion Error referencing id containing $

Viewing 2 reply threads
  • Author
    Posts
    • #22934
      Darin Davis
      Participant

        BACKGROUND: I need to copy the value of one field to another if a condition is met. This is what I have so far (just for testing/learning):

        
        
        function copyOneTimeFactor(factor){
            if (factor === "oneTimeFactorAmt1") {
                alert("Called by " + factor + " rule. onetimeAmt1 = " + jQuery("#onetimeAmt1_cc2ba976-715e-44b1-a3e3-a2c6f5992382_$CurrencyField").val);
            }
            return(true);
        }

        I copied the input field id from Chrome Developer Tools (screen capture attached).

        In testing the custom JS, I’m getting the message:

        Syntax error, unrecognized expression: #onetimeAmt1_cc2ba976-715e-44b1-a3e3-a2c6f5992382_$CurrencyField

        (screen capture attached)

        If I remove the $, instead of an error message, I get 12 lines of unintelligible code as the (apparent) value of the input field (screen capture attached).

        QUESTION: What is wrong with the way I’m referencing the field ID so that it constitutes a syntax error? Is there a better way to accomplish my goal than using jQuery to get/set the values of input form fields?

        Thanks for any assistance!

      • #22945
        Alexander Bautz
        Keymaster

          Hi,
          Addressing an item with id containing $ requires that you escape it like this:

          jQuery("#onetimeAmt1_cc2ba976-715e-44b1-a3e3-a2c6f5992382_\\$CurrencyField").val();

          You can however use this approach instead:

          var value = getFieldValue("onetimeAmt1"); // Please verify the field name
          // Copy it to another field
          setFieldValue("Name_of_field_to_write_to",value);

          Alexander

        • #22947
          Darin Davis
          Participant

            Thank you very much, Alexander!

            Darin

        Viewing 2 reply threads
        • You must be logged in to reply to this topic.