document.forms.gallery_form.submit is not a function
- by Keene Maverick
I swear, I have this exact thing working on another page. I'm such a javascript noob it's embarrassing...
function delete_gallery() {
var gallery = document.getElementById('gallery_id').value;
var form = document.getElementById('gallery_form');
form.setAttribute('action', 'index.php?action=delete§ion=galleries&id='+gallery);
document.forms['gallery_form'].submit();
}
Inspecting the element shows that it's updating the action correctly :
<form method="post" action="index.php?action=delete&section=galleries&id=12" name="gallery_form" id="gallery_form"><input type="hidden" value="12" id="gallery_id" name="gallery_id"><p>Name: <input type="text" name="name" value="Woo"></p><p>Description:<br><textarea name="description">Dee</textarea><input type="hidden" value="2" name="artist"></p><p><input type="submit" value="Submit" name="submit">
</p></form>
Here's the button I use to call the function, it's in a table below the form:
<button onclick="delete_gallery()" type="button">Delete Gallery</button>