title: How to change a form value dynamically and submit during onclick
body: <p>I am using onclick event in anchor tag. when i clcik the anchor, I am invoking a java script function where I change the value of one input element and submit the form. The value is changed but the form does not submit the value. Please help me on this. FYI that if i create an element and add in the form before submission, it works. Why is not working in the first scenario.</p>
  
  <pre><code>&lt;form name="form" &gt;    
      &lt;input type="hidden" name="input" value="test"/&gt;    
      &lt;a onclick='testMethod("test")'&gt;click &lt;/a&gt;    
  &lt;/form&gt;
  </code></pre>
  
  <p>script used is </p>
  
  <pre><code>function testMethod(value)
  {
      if(serviceName != null &amp;&amp; jQuery('#form') != null)
      {
          document.forms['form'].getElementById('input').value = value;
          document.forms['form'].action = jQuery('#newAction').val();
          document.forms['form'].submit();
      }
  }
  </code></pre>