未捕获的类型错误:无法设置 null 的属性(设置“值”)

发布于 2025-01-17 02:46:17 字数 3545 浏览 0 评论 0原文

您好,我需要帮助解决我网站上的这个java脚本问题,我阅读了堆栈溢出和谷歌上的所有帖子,但它似乎对我没有帮助。我收到错误Uncaught TypeError:无法设置null的属性(设置' value')

<!DOCTYPE html>
<html lang="en-US">
<head>
</head>
<body>

<div class="elementor-element elementor-element-bc48325 elementor-align-center elementor-widget elementor-widget-button" data-id="bc48325" data-element_type="widget" data-widget_type="button.default">
            <a href="#elementor-action%3Aaction%3Dpopup%3Aopen%26settings%3DeyJpZCI6IjExMzIiLCJ0b2dnbGUiOmZhbHNlfQ%3D%3D" class="elementor-button-link elementor-button elementor-size-sm" role="button" id="Social-media-manager">
                        <span class="elementor-button-text">Apply Now</span>
                    </a>
        </div>



//Popup form
<form class="elementor-form" method="post" name="New Form">
            <input type="hidden" name="post_id" value="1132"/>
            <input type="hidden" name="form_id" value="2c8531ad"/>
            <input type="hidden" name="referer_title" value="Careers" />
            <input type="hidden" name="queried_id" value="1304"/>

            <label for="form-field-name" class="elementor-field-label elementor-screen-only">Name</label>
            <input size="1" type="text" name="form_fields[name]" id="form-field-name" class="elementor-field elementor-size-sm  elementor-field-textual" placeholder="Name*" required="required" aria-required="true">
            
            <label for="form-field-field_1fc9713" class="elementor-field-label elementor-screen-only">Job Title*</label>
            <input size="1" type="text" name="form_fields[field_1fc9713]" id="form-field-field_1fc9713" class="elementor-field elementor-size-sm  elementor-field-textual" placeholder="Job Title*" required="required" aria-required="true">
                                            
            <label for="form-field-email" class="elementor-field-label elementor-screen-only">Email*</label>
            <input size="1" type="email" name="form_fields[email]" id="form-field-email" class="elementor-field elementor-size-sm  elementor-field-textual" placeholder="Email*" required="required" aria-required="true">
                                            
            <label for="form-field-message" class="elementor-field-label elementor-screen-only">Message</label>
            <textarea class="elementor-field-textual elementor-field  elementor-size-sm" name="form_fields[message]" id="form-field-message" rows="4" placeholder="Message" required="required" aria-required="true"></textarea>                </div>
            <input type="file" name="form_fields[field_501fb76][]" id="form-field-field_501fb76" class="elementor-field elementor-size-sm  elementor-upload-field" multiple="multiple">
                        
            <button type="submit" class="elementor-button elementor-size-sm">Apply now</button>
                
        
        </form>


<script>
var Social_media_manager = document.getElementById('Social-media-manager');

Social_media_manager.onclick = function(){
    document.getElementById('form-field-field_1fc9713').value = 'New value';
};
</script>

    </body>
</html>

这是网站的简化代码。有一个名为“立即应用”的按钮,按下它将调用名为“新表单”的弹出表单。使用我的 JavaScript,我尝试自动填充“form-field-field_1fc9713”,但它总是返回此错误。网站是使用 elementor 在 WordPress 上制作的,我使用位于底部的自定义代码功能

Hello i need help on fixing this java script issue on my website i read all post on stack overflow and google but it doesn't seem to help me .I am getting error Uncaught TypeError: Cannot set properties of null (setting 'value')

<!DOCTYPE html>
<html lang="en-US">
<head>
</head>
<body>

<div class="elementor-element elementor-element-bc48325 elementor-align-center elementor-widget elementor-widget-button" data-id="bc48325" data-element_type="widget" data-widget_type="button.default">
            <a href="#elementor-action%3Aaction%3Dpopup%3Aopen%26settings%3DeyJpZCI6IjExMzIiLCJ0b2dnbGUiOmZhbHNlfQ%3D%3D" class="elementor-button-link elementor-button elementor-size-sm" role="button" id="Social-media-manager">
                        <span class="elementor-button-text">Apply Now</span>
                    </a>
        </div>



//Popup form
<form class="elementor-form" method="post" name="New Form">
            <input type="hidden" name="post_id" value="1132"/>
            <input type="hidden" name="form_id" value="2c8531ad"/>
            <input type="hidden" name="referer_title" value="Careers" />
            <input type="hidden" name="queried_id" value="1304"/>

            <label for="form-field-name" class="elementor-field-label elementor-screen-only">Name</label>
            <input size="1" type="text" name="form_fields[name]" id="form-field-name" class="elementor-field elementor-size-sm  elementor-field-textual" placeholder="Name*" required="required" aria-required="true">
            
            <label for="form-field-field_1fc9713" class="elementor-field-label elementor-screen-only">Job Title*</label>
            <input size="1" type="text" name="form_fields[field_1fc9713]" id="form-field-field_1fc9713" class="elementor-field elementor-size-sm  elementor-field-textual" placeholder="Job Title*" required="required" aria-required="true">
                                            
            <label for="form-field-email" class="elementor-field-label elementor-screen-only">Email*</label>
            <input size="1" type="email" name="form_fields[email]" id="form-field-email" class="elementor-field elementor-size-sm  elementor-field-textual" placeholder="Email*" required="required" aria-required="true">
                                            
            <label for="form-field-message" class="elementor-field-label elementor-screen-only">Message</label>
            <textarea class="elementor-field-textual elementor-field  elementor-size-sm" name="form_fields[message]" id="form-field-message" rows="4" placeholder="Message" required="required" aria-required="true"></textarea>                </div>
            <input type="file" name="form_fields[field_501fb76][]" id="form-field-field_501fb76" class="elementor-field elementor-size-sm  elementor-upload-field" multiple="multiple">
                        
            <button type="submit" class="elementor-button elementor-size-sm">Apply now</button>
                
        
        </form>


<script>
var Social_media_manager = document.getElementById('Social-media-manager');

Social_media_manager.onclick = function(){
    document.getElementById('form-field-field_1fc9713').value = 'New value';
};
</script>

    </body>
</html>

this is simplified code of the website . There is a button called Apply now ones pressed it will call popup form called New form . with my JavaScript i am trying auto fill "form-field-field_1fc9713" but it always returns me this error . Website is made on WordPress using elementor and i am using custom code function placed at the bottom

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可可 2025-01-24 02:46:17

如果您将代码复制粘贴到 HTML 文件中,它将正常工作,并且输入将填充“新值”,您的问题是弹出表单。您在创建表单之前调用

document.getElementById('form-field-field_1fc9713')

并将返回 null。请在弹出窗口创建后调用此行

If You copy-paste your code to an HTML file it will work fine and the input will be populated with the 'new value' your problem is the popup form. you call

document.getElementById('form-field-field_1fc9713')

before form created and will return null. please call this line after popup creation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文