Pre-fill form field via URL in html

前端 未结 4 2206
一向
一向 2020-12-06 01:40

I am looking for a simple way to pre-fill a field in my contact form when ever a user clicks on a link that is given in some other page.

This is my contact form in h

4条回答
  •  一向
    一向 (楼主)
    2020-12-06 02:38

    You can retrieve your current url with window.location.href and then get the default message via a regular expression :

    var msg = window.location.href.match(/\?setmessagefield=(.*)/);
    document.getElementById("message").value = msg[1];
    

提交回复
热议问题