首页 > 解决方案 > 动态设置隐藏电子邮件字段的值不起作用

问题描述

使用以下代码,我试图设置两个字段,其中一个是正确设置的隐藏类型。另一个字段是隐藏在可见性中的电子邮件字段,并且没有设置。不知道为什么在设置隐藏类型时不会发生这种情况。请注意,我根据 FluentForms WordPress 插件中的条件逻辑隐藏了此电子邮件字段。此逻辑确保当基于前面字段的所有条件都为真时,此字段不会显示。

在此处输入图像描述

jQuery(".ff-btn-submit").click(function() {
  // Retrieve the Rep name of chosen representative.
  var repName = jQuery('#ff_124_dropdown option:selected').text();
  
  // Retrieve the email address of the chosen representative
  var repNameEmail = jQuery('#ff_124_dropdown option:selected').val();
  
  // Set the hidden email field to the Representative's email address.
  jQuery("input[name=email_1]").val(repNameEmail);
    
  // Set the hidden field to the Representative's name.
  jQuery("input[name=rep_name]").val(repName);
  
  console.log(repName + '' + repNameEmail);
});

电子邮件字段的 HTML 如下所示。

<div class="ff-el-input--content"><input type="email" name="email_1" id="ff_124_email_1" class="ff-el-form-control" placeholder="Sales Representative Email" data-name="email_1" style="background-image: url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABHklEQVQ4EaVTO26DQBD1ohQWaS2lg9JybZ+AK7hNwx2oIoVf4UPQ0Lj1FdKktevIpel8AKNUkDcWMxpgSaIEaTVv3sx7uztiTdu2s/98DywOw3Dued4Who/M2aIx5lZV1aEsy0+qiwHELyi+Ytl0PQ69SxAxkWIA4RMRTdNsKE59juMcuZd6xIAFeZ6fGCdJ8kY4y7KAuTRNGd7jyEBXsdOPE3a0QGPsniOnnYMO67LgSQN9T41F2QGrQRRFCwyzoIF2qyBuKKbcOgPXdVeY9rMWgNsjf9ccYesJhk3f5dYT1HX9gR0LLQR30TnjkUEcx2uIuS4RnI+aj6sJR0AM8AaumPaM/rRehyWhXqbFAA9kh3/8/NvHxAYGAsZ/il8IalkCLBfNVAAAAABJRU5ErkJggg==&quot;); background-repeat: no-repeat; background-attachment: scroll; background-size: 16px 18px; background-position: 98% 50%;"></div>

标签: javascriptjquery

解决方案


推荐阅读