Make dynamic form using javascript
Simple function to make form with one hidden value and submit this form. It can be used for deleting elements, or changing status from one to another.
It takes 3 parameters val - value to be submitted (usually ID of record in database), name - key of the post variable (like $_POST['name']) and attach - id of any div to attach form, it doesn't really matter which div, because form is hidden.
function makeform(val, name, attach) { var attachform = document.getElementById(attach); var form = document.createElement("form"); form.setAttribute("method", 'post'); form.setAttribute("action", ""); var inp = document.createElement("input"); inp.setAttribute("type", 'hidden'); inp.setAttribute("value", val); inp.setAttribute("name", name); form.appendChild(inp); attachform.appendChild(form); form.submit(); }
You can use it like this:
Then capture post through PHP and delete record
You may also be interested in:
Powered by BlogAlike.com










