js submit function with form'name as var

hi,
 the following code doesnt work, any idea what's wrong with it?
<form name="myform" action="index.php">
   Search: <input onclick=submitform('myform') type='button' name='go' value='go'>
</form> 
<SCRIPT language="JavaScript">
   function submitform(var_name) { document.var_name.submit(); }
</SCRIPT>

Open in new window

uk1900Asked:
Who is Participating?
 
Ashish PatelConnect With a Mentor Commented:
Or you can do this way too.

<form name="myform" action="index.php">
   Search: <input onclick=submitform(document.myform) type='button' name='go' value='go'>
</form>
<SCRIPT language="JavaScript">
   function submitform(frmobj) { frmobj.submit(); }
</SCRIPT>
0
 
Ashish PatelCommented:
Write it like this

<form name="myform" action="index.php">
   Search: <input onclick=submitform('myform') type='button' name='go' value='go'>
</form>
<SCRIPT language="JavaScript">
   function submitform(var_name) { eval('document.' + var_name).submit(); }
</SCRIPT>
0
 
uk1900Author Commented:
works  perfectly!
0
All Courses

From novice to tech pro — start learning today.