Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript根据另一个字段值更改Contact 7表单字段值_Javascript_Contact Form 7_Contact Form - Fatal编程技术网

如何使用javascript根据另一个字段值更改Contact 7表单字段值

如何使用javascript根据另一个字段值更改Contact 7表单字段值,javascript,contact-form-7,contact-form,Javascript,Contact Form 7,Contact Form,我想从用户的要求进入他们的网站,如果用户在下拉字段中选择除访客档案以外的任何其他内容 默认Url字段值为空。如果用户配置文件下拉选择为“访问者”,则侦听器会将url字段设置为“https://example.com“else url设置为空,要求用户在发送表单之前输入url 请提供以下代码的帮助: 无论用户配置文件选择了什么,它在侦听器函数中总是默认为not Visitor 如果用户选择not Visitor,我测试了将url设置为一些虚拟https,但url字段值没有改变,这意味着我的代码也无

我想从用户的要求进入他们的网站,如果用户在下拉字段中选择除访客档案以外的任何其他内容

默认Url字段值为空。如果用户配置文件下拉选择为“访问者”,则侦听器会将url字段设置为“https://example.com“else url设置为空,要求用户在发送表单之前输入url

请提供以下代码的帮助:

  • 无论用户配置文件选择了什么,它在侦听器函数中总是默认为not Visitor
  • 如果用户选择not Visitor,我测试了将url设置为一些虚拟https,但url字段值没有改变,这意味着我的代码也无法将url设置为特定值
  • 仅供参考-您会注意到使用[group]来隐藏/显示Url输入字段,根据该字段进行美容隐藏/显示

    谢谢你的帮助

    [编辑]-下面的工作代码。最终删除并使用id:来分配和使用变量

    联系人7表格->表格选项卡代码:

    <div class="wpcf7-inline-wrapper">
    <p class="wpcf7-inline-field">[text* your-firstname watermark "First Name"]</p>
    <p class="wpcf7-inline-field">[text* your-lastname placeholder "Last Name"]</p>
    </div>
    
    <div class="wpcf7-inline-wrapper">
    <p class="wpcf7-inline-field">[email* your-email "Email"] </p>
    </div>
    
    <div class="wpcf7-inline-wrapper">
    <p class="wpcf7-inline-field">
    <label id="dropDownProfile">
    [select* your-profile id:dropDownProfile first_as_label "-- Choose Profile Type --" "Visitor" "Engineer"]
    </label>
    </p></div>
    
    [group PortfolioWebsite]
    <p class="wpcf7-inline-field">[url* your-url id:userWebsite] </p>
    [/group]
    
    <p>[textarea your-message "Message"] </p>
    
    [submit class:btn class:btn-accent "Contact"]
    
    <script>
    document.getElementById("dropDownProfile").addEventListener("change", displayUrl);
    function displayUrl() 
    {
    var currProfile=document.getElementById("dropDownProfile").value;
    console.log(currProfile);
    if (currProfile == "Visitor") 
        {
            document.getElementById("userWebsite").value = "https://dummyplaceholder.com";
    } 
    else 
        {
            console.log("at Exhibt");
            document.getElementById("userWebsite").value = "";
        }
    }
    </script>
    
    
    

    [text*您的名字水印“First Name”]

    [文本*您的姓氏占位符“姓氏”]

    [电子邮件*您的电子邮件“电子邮件”]

    [选择*您的配置文件id:dropDownProfile first_作为标签”--选择配置文件类型--“访问者”“工程师”]

    [集团PortfolioWebsite]

    [url*您的url id:userWebsite]

    [/组] [textarea您的信息“message”]

    [提交类别:btn类别:btn重音“联系人”] document.getElementById(“dropDownProfile”).addEventListener(“更改”,显示URL); 函数displayUrl() { var currProfile=document.getElementById(“dropDownProfile”).value; console.log(currProfile); 如果(currProfile==“访客”) { document.getElementById(“用户网站”).value=“https://dummyplaceholder.com"; } 其他的 { 控制台日志(“在展会上”); document.getElementById(“用户网站”).value=“”; } }
    仅供参考,我发现这个链接是一个很好的起点

    最终没有使用分配/使用变量,而是使用id: 使用getElementById(“hereTheID”).value在侦听器上赋值

    在问题中编辑工作代码


    干杯

    仅供参考,我发现这个链接是一个很好的起点

    最终没有使用分配/使用变量,而是使用id: 使用getElementById(“hereTheID”).value在侦听器上赋值

    在问题中编辑工作代码


    cheers

    您的代码包含多个明显的错误,这让我相信您只是简单地复制和粘贴了其中的大部分,实际上并不理解javascript DOM。首先,您需要在表单代码中使用与
    document.getElementById
    中相同的id。其次,它只是
    element.value
    ,而不是
    element.display.value
    您的代码包含多个明显的错误,这让我相信您只是简单地复制和粘贴了大部分内容,实际上并不理解javascript DOM。首先,您需要在表单代码中使用与
    document.getElementById
    中相同的id。其次,它只是
    元素.value
    ,而不是
    元素.display.value