Почему я получаю ‘querySelector’ из NULL? Что я делаю не так в этом коде?

Почему я получаю ‘querySelector’ со значением NULL? Что я делаю не так в этом коде?

Я реализовал код на CMS Magnolia, задача состоит в том, чтобы получить значения формы в другой скрытой форме (из Marketo). Код прекрасно работает в версии сообщества Магнолия, но не в производственной среде. Пожалуйста, помогите с кодом. Что здесь не так?

HTML-код для веб-формы Magnolia:

 {amp}lt;form id="commandDEmarketo_test" class="webtrekkHelper_configs eineSeite" data-webtrekk-forminstall="true" data-mwf-target="/formulare/servlet/form;webforms=A0FE63A9C0A3C637292A391D2D5F6662?_uid=DEmarketo_test{amp}amp;amp;lang=de_DE{amp}amp;amp;_view=webform" data-webtrekk-temp-append-base-contentid="." data-mwf-id="DEmarketo_test" action="/formulare/servlet/form;webforms=A0FE63A9C0A3C637292A391D2D5F6662" method="post" enctype="multipart/form-data" accept-charset="utf-8" onsubmit="return false;" data-mktorelay-formid="1038"{amp}gt; {amp}lt;input type="hidden" name="audience" value="UIP"{amp}gt; {amp}lt;input type="hidden" name="revisionNr" value="24593"{amp}gt; {amp}lt;input type="hidden" name="formRevisionNr" value="23509"{amp}gt; {amp}lt;input type="hidden" name="wt_form" value="1"{amp}gt; {amp}lt;input type="hidden" name="_mwfToken:DEmarketo_test" value="D4486376922829AE0BA1C3BA5F935941"{amp}gt; {amp}lt;div id="form-top"{amp}gt;{amp}lt;/div{amp}gt; {amp}lt;ul id="crumbs"{amp}gt; {amp}lt;li class="selected "{amp}gt; {amp}lt;a href="#" style="height: 0px; padding-right: 0px;"{amp}gt; {amp}lt;div{amp}gt; {amp}lt;span{amp}gt; {amp}lt;/span{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;/a{amp}gt; {amp}lt;/li{amp}gt; {amp}lt;li class="last-child"{amp}gt; {amp}lt;a href="#" style="height: 0px; padding-right: 0px;"{amp}gt; {amp}lt;div{amp}gt; {amp}lt;span{amp}gt; Success {amp}lt;/span{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;/a{amp}gt; {amp}lt;/li{amp}gt; {amp}lt;/ul{amp}gt; {amp}lt;div class="innerForm"{amp}gt; {amp}lt;ul class=""{amp}gt; {amp}lt;div class=""{amp}gt; {amp}lt;li data-mwf-container="mwf0301fe8ca93a" class="mwf-field mwf-bold mwf-italic h-odd"{amp}gt; {amp}lt;script{amp}gt; var d = document.getElementById("commandDEmarketo_test"); d.setAttribute("data-mktorelay-formid", "1038"); {amp}lt;/script{amp}gt; {amp}lt;/li{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;div class=" none"{amp}gt; {amp}lt;li data-mwf-container="mwf23e481e7bdc0" class="mwf-field h-even"{amp}gt; {amp}lt;label class="mwf-label" for="mwf23e481e7bdc0"{amp}gt; Vorname {amp}lt;/label{amp}gt; {amp}lt;div class="mwf-input"{amp}gt; {amp}lt;input id="mwf23e481e7bdc0" name="vorname" class="mwf-text " data-mwf-id="mwf23e481e7bdc0" type="text" value=""{amp}gt; {amp}lt;p class="mwf-error"{amp}gt;{amp}lt;/p{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;/li{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;div class=" none"{amp}gt; {amp}lt;li data-mwf-container="mwf08d9bc1fbf81" class="mwf-field h-odd"{amp}gt; {amp}lt;label class="mwf-label" for="mwf08d9bc1fbf81"{amp}gt; Nachname {amp}lt;/label{amp}gt; {amp}lt;div class="mwf-input"{amp}gt; {amp}lt;input id="mwf08d9bc1fbf81" name="nachname" class="mwf-text " data-mwf-id="mwf08d9bc1fbf81" type="text" value=""{amp}gt; {amp}lt;p class="mwf-error"{amp}gt;{amp}lt;/p{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;/li{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;div class=""{amp}gt; {amp}lt;input id="versteckt" name="versteckt" data-mwf-id="mwf4531354a7b12" type="hidden" value=""{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;div class=""{amp}gt; {amp}lt;li data-mwf-container="mwf568b7206cb24" class="mwf-field "{amp}gt; {amp}lt;label class="mwf-label"{amp}gt; Radio {amp}lt;/label{amp}gt; {amp}lt;div class="mwf-input"{amp}gt; {amp}lt;fieldset data-mwf-fieldset="mwf568b7206cb24"{amp}gt; {amp}lt;span class="mwf-option"{amp}gt; {amp}lt;input id="mwf568b7206cb24_A" name="radio" class="mwf-radio" data-mwf-id="mwf568b7206cb24" type="radio" value="A"{amp}gt; {amp}lt;label for="mwf568b7206cb24_A"{amp}gt;Option a{amp}lt;/label{amp}gt; {amp}lt;div class="clearfix"{amp}gt;{amp}lt;/div{amp}gt; {amp}lt;/span{amp}gt; {amp}lt;span class="mwf-option"{amp}gt; {amp}lt;input id="mwf568b7206cb24_B" name="radio" class="mwf-radio" data-mwf-id="mwf568b7206cb24" type="radio" value="B"{amp}gt; {amp}lt;label for="mwf568b7206cb24_B"{amp}gt;Option 2{amp}lt;/label{amp}gt; {amp}lt;div class="clearfix"{amp}gt;{amp}lt;/div{amp}gt; {amp}lt;/span{amp}gt; {amp}lt;/fieldset{amp}gt; {amp}lt;p class="mwf-error"{amp}gt;{amp}lt;/p{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;/li{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;div class=""{amp}gt; {amp}lt;li data-mwf-container="mwf0364ecee4a3f" class="mwf-field h-even"{amp}gt; {amp}lt;label class="mwf-label" for="mwf0364ecee4a3f"{amp}gt; Dropdown {amp}lt;/label{amp}gt; {amp}lt;div class="mwf-input"{amp}gt; {amp}lt;select id="mwf0364ecee4a3f" name="dropdown" class="mwf-select mwf-multiple " data-mwf-id="mwf0364ecee4a3f"{amp}gt; {amp}lt;option id="mwf1eb0a105558d_DEmarketo_test" value="1"{amp}gt;erster Wert{amp}lt;/option{amp}gt; {amp}lt;option id="mwf8dce584a8bef_DEmarketo_test" value="2"{amp}gt;zweiter Wert {amp}lt;/option{amp}gt; {amp}lt;/select{amp}gt; {amp}lt;p class="mwf-error"{amp}gt;{amp}lt;/p{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;/li{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;/ul{amp}gt; {amp}lt;ul{amp}gt; {amp}lt;li data-mwf-container="_finish_mwfdf9ed4d75291" class="mwf-button mwf-next"{amp}gt; {amp}lt;input type="button" value="Submit" data-mwf-submit="{{amp}amp;quot;type{amp}amp;quot;:{amp}amp;quot;finish{amp}amp;quot;}" class="webtrekkHelper_observe" data-webtrekk-formsubmit="" data-webtrekk-linkid-area="Content" data-webtrekk-linkid-element="Button" data-webtrekk-linkid-name="Submit" data-webtrekk-linkid-target-append-base-contentid=".Success"{amp}gt; {amp}lt;/li{amp}gt; {amp}lt;/ul{amp}gt; {amp}lt;ul{amp}gt; {amp}lt;li class="mwf-pager"{amp}gt; {amp}lt;p{amp}gt; {amp}lt;span{amp}gt;1{amp}lt;/span{amp}gt;/{amp}lt;span{amp}gt;2{amp}lt;/span{amp}gt; {amp}lt;/p{amp}gt; {amp}lt;/li{amp}gt; {amp}lt;/ul{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;/form{amp}gt; 

Сценарий, который я запускаю,

 {amp}lt;script{amp}gt; MktoForms2.loadForm("https://app-lonXX.marketo.com", "162-XXX-XXX", 10XX); document.addEventListener('readystatechange', function() { if(document.readyState === "complete") { init(); } }); function init() { var customForm = document.querySelector("#commandDEmarketo_test"), customFormButton = customForm.querySelector("input[type='button']"); customFormButton.addEventListener("click",function(customFormSubmitEvent){ customFormSubmitEvent.preventDefault(); customFormButton.disabled = true; MktoForms2.whenReady(function(mktoForm) { mktoForm.addHiddenFields({ "FirstName": customForm.querySelector("#mwf23e481e7bdc0").value, "LastName": customForm.querySelector("#mwf08d9bc1fbf81").value }); mktoForm.submit(); }); }); } {amp}lt;/script{amp}gt; 

Ошибка :

Uncaught TypeError: Невозможно прочитать свойство ‘querySelector’ с нулевым значением в init (marketo-test: 538) в HTMLDocument. (Marketo-тест: 526)

Понравилась статья? Поделиться с друзьями:
JavaScript & TypeScript
Adblock
detector