В настоящее время я смог получить URL для передачи переменной, так как MyWebsite.com/contactus?product_Name форма. < /p>
Код: Выделить всё
function getQueryParam(param) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(param);
}
const productName = getQueryParam('product_name');
if (productName) {
const productField = document.getElementById('product_name');
if (productField) {
productField.value = decodeURIComponent(productName);
}
}
< /code>
, кажется, происходит, так это то, что в тот момент, когда страница загружается, она заполняется, а затем сразу же очищается. Не уверен, почему. Here's the code to the webpage- I'm trying to autofill into the "Subject" which id is "obmoxynau18w" on the form (I think that's an odoo thing):
Contact us
Contact us about anything related to our company or services.
We'll do our best to get back to you as soon as possible.
Name *
Phone Number
Email
*
Subject *
Question
*
[url=#]Submit[/url]
function getQueryParam(param) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(param);
}
const productName = getQueryParam('product_name');
if (productName) {
const productField = document.getElementById('obmoxynau18w');
if (productField) {
productField.value = decodeURIComponent(productName);
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... -correctly
Мобильная версия