title: How to pass form name dynamically in to a javascript method?
body: <p>I am trying to pass form name dynamically. But this script is showing an error.</p>
  
  <p><strong>"document.formName is undefined".</strong> How to solve this. Thanks in advance.</p>
  
  <pre><code>&lt;script language="javascript"&gt;
  
  function showAll(form,fieldName) {
      var formName = form.name;
      alert(formName);
      document.formName.search_mode.value = "";   
      document.formName.fieldName.value="";
      document.formName.submit(); 
  }
  &lt;/script&gt;
  &lt;form name = "dealsManagement" method="post" action="&lt;?=$_SERVER['PHP_SELF']?&gt;"&gt;
  &lt;input type="hidden" name="search_mode" value="&lt;?php echo $_REQUEST['search_mode'];?&gt;" &gt;
  &lt;table border="0" cellpadding="0" cellspacing="0" align="center" width="400" style="padding:2px; border:#ccc solid 1px; margin:15px auto 15px auto;"&gt;
  &lt;tr&gt;
  &lt;td colspan="2" class="text3" align="center" height="35" bgcolor="#cccccc"&gt;Search&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td width="153" height="35" align="right" class="text2" style="padding-right:10px;"&gt;Search By  City:&lt;/td&gt;
  &lt;td width="245"&gt;&lt;input type="text" name="city" value= "&lt;?php echo $_POST['city']; ?&gt;" size="24" &gt;&lt;/input&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td height="30"&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&lt;input name="button" type="button" class="btn" onClick="javascript:dealSearchCity()" value="Search" /&gt;
  &lt;input name="btnShowAll" type="button" class="btn"value="Show All" onClick="javascript:showAll(this.form,'city');" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>