Skip Navigation

[Resolved] How to select input text field with jquery (not cred, not views)

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to access the value of a select field in a Form using jQuery.

Solution: Use the "name" attribute equals selector:

jQuery(".wpt-form-textfield[name='wpcf[relationship][optie-3]']").val();

Relevant Documentation:
https://api.jquery.com/attribute-equals-selector/

This support ticket is created 5 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 3 voices.

Last updated by Patrick 5 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1163747
Schermafbeelding 2018-12-11 om 14.30.29.jpg

Hi,

How can i select an input text field with jquery? See attactched image.

What i have is not working:

jQuery(".wpt-form-textfield[data-wpt-id='wpcf-optie-3']").val();

Source:
<input type="text" id="-textfield-1-1544535384" name="wpcf[relationship][optie-3]" value="ddd" types-related-content="1" class="wpt-form-textfield form-textfield textfield" data-wpt-type="textfield" data-wpt-id="wpcf-optie-3" data-wpt-name="wpcf[relationship][optie-3]">

#1164064

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Patrick,

Thank you for contacting our support forum.

Could you try using the Name attribute instead of the data id to retrieve the information from the field ?

Thanks,
Shane

#1167871

how?

#1168949

Hi, Shane is on holiday so I'm following up on his open tickets. I believe he was talking about using the jQuery attribute selector. Like so:

jQuery(".wpt-form-textfield[name='wpcf[relationship][optie-3]']").val();

https://api.jquery.com/attribute-equals-selector/

#1171189

My issue is resolved now. Thank you!