Populate field with a value from Javascript

Adam McGill created the topic: Populate field with a value from Javascript

Hi.

I have a value from Javascript (runs on form load) and I need to populate that value into a field on my form.

How can I do this please.

Regards

Adam

#41489

Please Log in or Create an account to join the conversation.


Support replied the topic: Populate field with a value from Javascript

Dear Adam,

Did your write this Javascript code in Form Options > Additional Javascript? If not, you can do that, however, it is not very significant, just wanted to let you know.

As for your question, please add an input and assign the variable you have created to its jQuery object. the code should be approximately the following:

jQuery(#field_ID).val(yourVariableName);

Where field_ID is the exact ID of your form input.
Thank you!


Best regards,
Web-Dorado team


Joomla extensions ,
Wordpress plugins ,
Drupal modules
#41549
The following user(s) said Thank You: Adam McGill

Please Log in or Create an account to join the conversation.


Bob Garrett replied the topic: Populate field with a value from Javascript

I am struggling to achieve the same but with little knowledge of javascript.

I have tried variations of the following, can you explain what I should have to set the contents of the field wdform_1_element24 to "Bob"?

// Occurs before the form is loaded
function before_load() {
jQuery(#wdform_1_element24).val("Bob");
}

// Occurs just before submitting the form
function before_submit() {
// IMPORTANT! If you want to interrupt (stop) the submitting of the form, this function should return true. You don't need to return any value if you don't want to stop the submission.
}

// before form reset
function before_reset() {

}

#77315

Please Log in or Create an account to join the conversation.


Agapi G. replied the topic: Populate field with a value from Javascript

Hello Bob!

Thank you for posting about this!

The jQuery code is alright, but there might be a conflict on your form, that is not letting it to run properly. Could you please give the link to your form page? We'll check it and see why the code is not running properly.

Thanks! Have a great day!


Kind regards,
Agapi G.
Web-Dorado team
#77351

Please Log in or Create an account to join the conversation.


Bob Garrett replied the topic: Populate field with a value from Javascript

#77371

Please Log in or Create an account to join the conversation.


Agapi G. replied the topic: Populate field with a value from Javascript

Thank you for the link, Bob!

Looks like there is a Javascript conflict with your website theme. It is adding <p> tags around the script, and that is why your code is not executing. Please check the attached screenshot, where I have mentioned these tags.

If you are not sure where to fix this issue in the theme, we can implement a workaround for you. Please submit a support ticket by sending temporary WordPress administrator access to us through this form .

Don't forget to mention the link to this forum thread in your message.
Thanks! Have a wonderful Friday!


Kind regards,
Agapi G.
Web-Dorado team
#77417
Attachments:

Please Log in or Create an account to join the conversation.


Bob Garrett replied the topic: Populate field with a value from Javascript

I am awaiting feedback from the theme author.
However, I note that it is not just this script which appears to be excluded but also some other script from your plugin. Am I right and what effect might this be having?
Thanks.

#77473

Please Log in or Create an account to join the conversation.


Bob Garrett replied the topic: Populate field with a value from Javascript

I may have identified the problem.
However the field value is still not loading.
Could you check the page again?
www.ccrc.co.uk/temp/

#77475

Please Log in or Create an account to join the conversation.


Bob Garrett replied the topic: Populate field with a value from Javascript

Now partly sorted.
The variable needed to be in quotes:
jQuery("#wdform_1_element24").val('Bob');

However, the value appears in the field in italics but as soon as you click to edit the field it disappears.My goal was to allow users to edit the value prior to submission.

Also, how do I pass the value of a variable from php into this value?

Thanks again

#77477

Please Log in or Create an account to join the conversation.


Agapi G. replied the topic: Populate field with a value from Javascript

Hello Bob!

Thank you for providing the details. Our developers have checked and they are suggesting you to use this jQuery code instead:

jQuery("#wdform_1_element24").val(fullname).removeClass("input_deactive").addClass("input_active");

Could you please give this a try and let me know if it works?
Thanks! Have a wonderful day!


Kind regards,
Agapi G.
Web-Dorado team
#77569

Please Log in or Create an account to join the conversation.


Bob Garrett replied the topic: Populate field with a value from Javascript

That works. Terrific.
Many thanks for your assistance.
Great support.

#77763

Please Log in or Create an account to join the conversation.


Agapi G. replied the topic: Populate field with a value from Javascript

That's wonderful, Bob!

We are glad to know the code worked on your website. Please don't hesitate to let our team know any time you have other support requests or questions. We'll be happy to assist!

And in case you've got a few minutes, please share your customer experience with Form Maker on WordPress.org. We highly value and appreciate your comments, they are a big contribution to for our team!

Let me provide the link:
wordpress.org/support/plugin/form-maker/reviews/

Thanks so much! Have a wonderful day!


Kind regards,
Agapi G.
Web-Dorado team
#77793

Please Log in or Create an account to join the conversation.


Time to create page: 0.258 seconds
Powered by Kunena Forum

WORLD-CLASS SUPPORT

We are here for you every step of the way. Turn to our support with any questions you might have about our products and services. Our experienced customer care team is available to help you as fast as we possibly can.

Contact us