There is a line like

email=email@ya.ru&login=Vasua&uid=54248 

How to automatically fill out the form

 <form> <input type="text" name="email">E-mail<Br> <input type="text" name="login">Login<Br> <input type="text" name="uid">UID</p> <p><input type="submit"></p> </form> 
  • @ splash58, do not give only links to the answer. Plus - make out as the answer, the comment cannot be accepted. - user207618
  • This is not an answer, it is a link to a similar question in English SO. Since it is in English, it’s probably wrong to call a duplicate, and rewriting as an answer is even stupider :) - splash58
  • @ splash58, that's exactly what you need - let everyone who is not familiar with English see this solution. Just leave at the end a link to the answer - something like a copyright. - user207618 pm
  • then, probably, it is more correct to do this as a general answer. Good job for moderators :)). I don’t know if the rating allows me, but I don’t know how to do it anyway - splash58

1 answer 1

 let str = `email=email@ya.ru&login=Vasua&uid=54248`; function parseQuery(query = '') { let tmp = {}; String(query).trim().split('&').forEach(e => tmp[decodeURIComponent(e.split('=')[0])] = decodeURIComponent(e.split('=')[1])); return tmp; } let obj = parseQuery(str); // Декодируем строку запроса в объект document.addEventListener('DOMContentLoaded', e => { // Дожидаемся загрузки DOM, иначе элементов не найдёшь Object.keys(obj).forEach(e => { // Перебираем все ключи, т.е. name let el = null; if ((el = document.querySelector(`[name=${e}]`)) !== null) { // Ищем элемент по name el.value = obj[e]; // Если нашли, то вставляем значение } else { console.info(`Element '[name=${e}]' not found!`); } }); }); 
 <form> <input type="text" name="email">E-mail <br /> <input type="text" name="login">Login <br /> <input type="text" name="uid">UID <p> <input type="submit"> </p> </form>