Pre select dropdown option
-
We need to preselect dropdown option from url. Something like http://www.mywebsite.com/form/?dropdown=option2
The page I need help with: [log in to see the link]
-
Hi, @maasut!
Thanks for posting your question!
Unfortunately, Form Maker does not have this functionality by default.However, you can get this by writing a few lines of Javascript code on Form Options > Javascript tab. Please try this.
Firstly, add these two it inside
before_load()function:value = getParameterByName('field'); jQuery("#hidden_id").val(value);Afterwards add the following code outside of all built-in functions in the editor:
function getParameterByName(name, url) { if (!url) { url = window.location.href; } name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); }Let us know if this helps.
Cheers!Thanks!¿Like this?
// Occurs before the form is loaded function before_load() { value = getParameterByName('field'); jQuery("#hidden_id").val(value); } // 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. } // Occurs just before resetting the form function before_reset() { } function getParameterByName(name, url) { if (!url) { url = window.location.href; } name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); }How should be the url address? Something http://www.mywebpage.com/?id=value
Hello, @maasut!
The code is correct, but let me note, that instead of #hidden_id you need to place the exact ID of the select box field (e.g.
#wdform_2_element3).You can get it from the front-end of your form, by inspecting the element.
The URL will be generated as the following:
http://www.mywebpage.com/?fieldname=valueLet me know in case you have questions.
Cheers!Thanks for help, but not working
// Occurs before the form is loaded function before_load() { value = getParameterByName('field'); jQuery("#wdform_5_element54").val(value); } // 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. } // Occurs just before resetting the form function before_reset() { } function getParameterByName(name, url) { if (!url) { url = window.location.href; } name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); }Now the dropdown are unselected.Sorry my bad english.
-
This reply was modified 8 years, 6 months ago by
maasut.
When I use the http://www.mywebpage.com/?fieldname=value the dropdown field are empty.
Hi, @maasut!
Sorry, that’s my mistake. Since the name of the parameter in the following line is
field:
value = getParameterByName('field');You will need to have the URL with the following format:
http://www.mywebpage.com/?field=valueOr you can set it to any text, but these two strings need to match. Hope this helps.
Cheers!Thank´s is working but these fields have conditional behaviors but are not working at the time of loading the page please look this link https://www.earth.ac.cr/en/study-at-earth/short-term-international-programs/rai-program-application/?field=Spanish_Learning_Courses and again thank you for help.
Hi, @maasut!
I am happy to inform you, that our development team has resolved the problem on your website. They have commented the following part in Form Options > Javascript:
value = getParameterByName("field"); jQuery("#wdform_5_element54").val(value);and added the code below to /form-maker/frontend/views/FMViewForm_maker.php instead:
jQuery(document).ready(function () { value = getParameterByName("field"); jQuery("#wdform_5_element54").val(value); }Could you have a look? Please test and confirm if the problem is fixed.
Thank you! Have a great day! -
This reply was modified 8 years, 6 months ago by
The topic ‘Pre select dropdown option’ is closed to new replies.