title: JSP - Continue only if this id exists
body: <p>I am very new to JSP. I have following code.</p>
  
  <pre><code>         var code = $('#codeForm').find('#disCode');
           var disCodeVal = disCode.val().trim();
  </code></pre>
  
  <p>The #discode is an input field which is either defined or not based on some condition. How can i add an if condition to test if #discode is defined and only if it is defined then proceed to getting disCodeVal?</p>
  
  <p>EDIT: Based on a condition when the page loads it will either have an input field called disCode or not. </p>
  
  <pre><code>  &lt;c:if test="${url eq 'test'}"&gt;                                     
           &lt;a:fixedGridColumn position="${'last'}" fixedColumn="${'left'}" &gt;
                &lt;a:textInput id="disCode" name="code" value="${disCode}" required="true" /&gt;
          &lt;/a:fixedGridColumn&gt;
    &lt;/c:if&gt;
  </code></pre>
  
  <p>Then when submit button is clicked a function is attached to it as follows.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
   P.when("jQuery").execute(function($) {
  
       $("#submitBtn").click( function(e) { 
              var code = $('#codeForm').find('#disCode');
              var disCodeVal = disCode.val().trim();
              ..// more validation code for other input fields which are always present
  </code></pre>
  
  <p>Now i want to only activate the above two lines on the click of the button if disCode input field exists. </p>