Button post HTML

user434885 picture user434885 · Jan 12, 2011 · Viewed 37k times · Source

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>

Answer

Xavier Barbosa picture Xavier Barbosa · Jan 12, 2011

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();
}