Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: document.getElementById(...).submit is not a function

I'm having an error that I can't find the solution and I don't have to use jQuery; I don't have any div with submit as name

My code is

<!DOCTYPE html>    
<html>    
<head>    
<script>    
function formSubmit()    
{    
     document.getElementById('web').submit();    
}    
</script>    
</head>    
<body>    
<form action="class003.php" id="g_form" method="POST">    
<input type="text" name="f1" value="">    
</form>    
<div id="web" onclick="formSubmit()">click</div>    
</body>    
</html>

on chrom I'm getting this error

Uncaught TypeError: document.querySelector(...).submit is not a function at formSubmit (test2.html:8) at HTMLDivElement.onclick (test2.html:19)

on Firefox the same error

TypeError: document.getElementById(...).submit is not a function[Learn More]

like image 780
Bynd Avatar asked May 31 '26 12:05

Bynd


1 Answers

You need to submit form not the div

Make it

document.getElementById('g_form').submit();    
like image 177
gurvinder372 Avatar answered Jun 03 '26 00:06

gurvinder372