PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Accessing Form Elements Programmatically

  1. etrakdev
    Member

    I need to access and update fields, such as quantity from a product field, from the Javascript function gform_product_total. I've tried doing it with something like:

    var qtyProduct = $("input[name=input_5.3]").val();

    However, this throws an error "$ is not a function".

    What is the right way of referencing form element values from within that function?

    Posted 12 years ago on Thursday May 3, 2012 | Permalink
  2. kyle
    Member

    Use jQuery instead of $

    That is the standard way of using jQuery in WordPress.

    var qtyProduct = jQuery("input[name=input_5_3]").val();

    Posted 12 years ago on Thursday May 3, 2012 | Permalink
  3. etrakdev
    Member

    Yeah, I had tried that, too, but there must be a syntax error with the element name reference "Syntax error, unrecognized expression: [name=input_5.3]".

    I'll keep digging. Thanks for your input, Kyle.

    Posted 12 years ago on Thursday May 3, 2012 | Permalink
  4. etrakdev
    Member

    Just a quick follow-up for others running into this issue:

    A quick search shows that the proper syntax should be:

    var qtyProduct = jQuery('input[name="input_5_3"]').val();

    Note the single and double quotation marks.

    Posted 12 years ago on Thursday May 3, 2012 | Permalink