input в ссылку не передает остаток url?text=мой текст

Рейтинг: 1Ответов: 1Опубликовано: 07.03.2023

Код ниже работает. Но как добавить продолжение ссылки, например, такой ?text=мой текст

<form name="idform">
    <input type="tel" name="id" placeholder="номер с кодом страны">
    <input type="button" value="Отправить" 
           onclick="location.href='https://wa.me/'+escape(document.forms['idform'].elements['id'].value)">
</form>

Ответы

▲ 1Принят

Надо просто немного дополнить формируемую строку:

<form name="idform">
    <input type="tel" name="id" placeholder="номер с кодом страны">
    <input type="hidden" id="vizHid" name="vizitka" value="?text=$link">
    <input type="button" value="Отправить"
           onclick="location.href='https://example.com/'+escape(document.forms['idform'].elements['id'].value)+document.forms['idform'].elements['vizHid'].value">
</form>