• Resolved Justine

    (@dangergoob)


    Hello, I am using JavaScript to dynamically load a select field’s options. Those load just fine, but when a user submits the form, the error message “Selected Value Does Not Exist” pops up underneath that field. Is there a step I may be missing? The field has the class “.propDrop” assigned to it, and arraySelect is an array of the options.

    if ( arraySelect.length >= 1 ) {

    ? ? ? ? //creates the options in the dropdown

    ? ? ? ? for(var j=0; j<arraySelect.length; j++) {

    ? ? ? ? ? ? var prop = arraySelect[j].property;

    ? ? ? ? ? ? jQuery('.propDrop div select').append('<option value="' + prop + '" data-email="'+ arraySelect[j].email +'" data-id="'+ arraySelect[j].id +'">' + prop + '</option>');

    ? ? ? ? }

    ? ? }

    ? ? else {

    ? ? ? ? jQuery('.propDrop').remove();

    ? ? }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @dangergoob

    I hope you’re well today!

    That’s correct, it won’t work this way. There’s additional data validation and sanitization for safety/security reasons to prevent various types of malicious/fraudulent activity that could be introduced via “unguarded” options.

    You’d need to use different way – a serever-side approach – to set the values to make sure they are properly recognized.

    Here are two examples that you can modify to build upon:

    1. This one sets select options based on the provided CSV file:

    https://gist.github.com/wpmudev-sls/6f1c8989a170b8f02026354ffe5ad24f

    2. This one copies options from one select field to another:

    https://gist.github.com/wpmudev-sls/d0dcbeba3378a4e7db9cf022cca35697

    While they are for a slightly different purpose, they both show how to set the options to make it work. Note that this is custom code and further custom modifications or providing dedicated solution is out of the scope of this support.

    Kind regards,
    Adam

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @dangergoob

    We didn’t hear back from you for quite some time so I’m marking it as resolved for now.

    However, if you still need assistance or have any additional questions, just let us know and we’ll get back to you.

    Best regards,
    Adam

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘“Selected Value Does Not Exist” on a dynamically generated field’ is closed to new replies.