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
Please Log in or Create an account to join the conversation.
- Topic Author
- Adam McGill
- Offline
- Fresh Boarder
- Posts: 4
- Thank you received: 0
8 years 4 months ago
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
Please Log in or Create an account to join the conversation.
8 years 4 months ago
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() {
}
Please Log in or Create an account to join the conversation.
- Bob Garrett
- Offline
- Junior Boarder
- Posts: 34
- Thank you received: 2
7 years 3 months ago
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
Please Log in or Create an account to join the conversation.
7 years 3 months ago
Bob Garrett replied the topic: Populate field with a value from Javascript
www.ccrc.co.uk/temp/
Thanks
Please Log in or Create an account to join the conversation.
- Bob Garrett
- Offline
- Junior Boarder
- Posts: 34
- Thank you received: 2
7 years 3 months ago
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
Please Log in or Create an account to join the conversation.
7 years 3 months ago
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.
Please Log in or Create an account to join the conversation.
- Bob Garrett
- Offline
- Junior Boarder
- Posts: 34
- Thank you received: 2
7 years 3 months ago
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/
Please Log in or Create an account to join the conversation.
- Bob Garrett
- Offline
- Junior Boarder
- Posts: 34
- Thank you received: 2
7 years 3 months ago
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
Please Log in or Create an account to join the conversation.
- Bob Garrett
- Offline
- Junior Boarder
- Posts: 34
- Thank you received: 2
7 years 3 months ago
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
Please Log in or Create an account to join the conversation.
7 years 3 months ago
Bob Garrett replied the topic: Populate field with a value from Javascript
That works. Terrific.
Many thanks for your assistance.
Great support.
Please Log in or Create an account to join the conversation.
- Bob Garrett
- Offline
- Junior Boarder
- Posts: 34
- Thank you received: 2
7 years 3 months ago
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
Please Log in or Create an account to join the conversation.
7 years 3 months ago