Skip Navigation

[Resolved] How to Add Id to toolset form fields

This support ticket is created 4 years 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by salimA 4 years ago.

Author
Posts
#1838567

I have a javascript code to pass value to the form filed using "document.getElementById("id").innerHTML", but I did not know where to put the "ID" in the HTML code(cred_field).
HTML code
[cred_field field='id-number1' force_type='field' class='form-control' output='bootstrap']

javascriptcode:
var c= document.getElementById("id").innerHTML="567865e";

#1838697

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

It somewhat depends on the kind of field input how you would achieve this.

Most fields can take a default value, which may be one way to set the value for a field.

If the field is a regular input (rather than checkboxes or a select dropdown with options, for example) then you can use the browser dev tools to inspect the input on the front-end and identify a specific selector for that field that you can use to target it with JavaScript, e.g. the name attribute will likely be the slug of the custom field with a 'wpcf-' prefix.

Also, you would probably set the value attribute rather than the innerHTML.

Rather than using document.getElementById (where you need an ID) you can use document.querySelector to target the input based upon the name attribute, e.g.

document.querySelector('input[name="wpcf-id-number1"]').value = '567865e';
#1839667

My issue is resolved now. Thank you for your support.