Javascript document.form.submit() not working with Firefox 4.0 and IE8

Sathyan A picture Sathyan A · Apr 5, 2011 · Viewed 11.4k times · Source

I'm trying to submit a form with javascript. Works fine with Firefox 3.6, but doesn't work in Firefox4.0 and IE8.

Code:

<table>  
     <tr>
     <td>  
     <form action='results.html' method='post' target='_blank' id='<% $question->{ QuestionID } %>'>  
     <input type='hidden' name='SurveyID' value='<% $surveyid %>'  
     <input type='hidden' name='responses' value='<% join ",", map { $_->{ srid } } @textresults %>'/>  
     <input type='hidden' name='question' value='<% $question->{ QuestionID } %>'/>  
Total Responses: (< a href='javascript: submitForm("<% $question->{ QuestionID } %>");' >View All< /a>)  
     </form>  
     </td>  
     </tr>  
</table>  

Javascript:

<script type='text/javascript'>  
function submitForm(id) {  
document.getElementById(id).submit();  
}  
</script>  

Any Idea what is wrong?

Answer

Rian Schmits picture Rian Schmits · Apr 5, 2011

First of all close the first input tag like this: <input type='hidden' name='SurveyID' value='<% $surveyid %>'/>. Also remove the spaces from the a tag, here: <a href and here: </a>