Link to home
Start Free TrialLog in
Avatar of uk1900
uk1900

asked on

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

Avatar of Ashish Patel
Ashish Patel
Flag of India image

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>
ASKER CERTIFIED SOLUTION
Avatar of Ashish Patel
Ashish Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of uk1900
uk1900

ASKER

works  perfectly!