Search code examples
javascripthtmlpostdata

Button post HTML


I need to use a button without using a form. How do I make it send post data to the browser?

I am using:

<button style="height: 100px; width: 300px" onClick="parent.location='form1.php'" >Fill survey</button>

Solution

  • You'll need to create a form in JavaScript, then submit it. Look at this code

    The HTML

    <button type="button" onclick="proceed();">do</button> 
    

    The JavaScript code

    function proceed () {
        var form = document.createElement('form');
        form.setAttribute('method', 'post');
        form.setAttribute('action', 'http://google.com');
        form.style.display = 'hidden';
        document.body.appendChild(form)
        form.submit();
    }