PHP isset和javascript

I have been searching for a few days on how to do this and I have yet to find an example of what I am looking for. Am I looking for the wrong thing?

Here is what I am trying to accomplish using the following code, I am reading in my error code and creating a link out of the error code.

<p><h4>Errors Returned (if any): </h4> 
    <a href="https://www.mysite.com/test/search_form.php?query=<?php echo $ERRORCODE; ?>">
        <?php echo $ERRORCODE; ?>
    </a>
</p>

I am then posting this information to my search form (below):

<?php
if (isset($_GET['query']))
{
    echo "javascript... and such.";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Search - Test Site 2013</title>
  </head>
    <table border="0" cellpadding="10">
      <tr>
        <td>
          <img src="images/test.png">
        </td>
        <td>
          <h1>Search - Test Site 2013</h1>
        </td>
      </tr>
    </table>
<body>
    <form action="search.php" method="GET" name="errorsearch">
        Search by Error Code
        <input type="text" name="query" />
        <input type="submit" value="Search" name="search"/>
    </form>
</body>
</html>

I am using (isset($_GET['query'])) to check if the error code has been passed over in the URL. I am able to successfully display a message or something silly, but I would like to submit the form and check for the error code text BUT ONLY IF query has been set.

It is my understanding that Javascript can do this but I am unsure exactly what is needed. I was researching Javascript submit buttons and on-click events but I think this is the opposite of what I want. I just need JS to initiate the button click.

Can someone point me in the right direction?

There are a number of different ways you could do this, but this question has already been answered elsewhere on this site. The answers here should help you: JavaScript code to stop form submission

If you need JS to initiate button click then just call function in javascript which is called on button click -> onClick listener.

You can create JS boolean variable to see if query was sent for example

var wasQuerySent = ""

and then you can test this if wasQuerySent has certain value.

Why Javascript at all? If I'm understanding correctly, you can handle all of this with PHP:

<?php
// Default to disabled state for submit button
$disabled = 'disabled="disabled"';
if (isset($_GET['query']))
{
    //echo "javascript... and such.";
    // if you get the $_GET['query'] then clear the submit's
    // disabled state
    $disabled = '';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>Search - Test Site 2013</title>
</head>
    <table border="0" cellpadding="10">
    <tr>
        <td>
        <img src="images/test.png">
        </td>
        <td>
        <h1>Search - Test Site 2013</h1>
        </td>
    </tr>
    </table>
<body>
    <form action="search.php" method="GET" name="errorsearch">
        Search by Error Code
        <input type="text" name="query" />
        <input type="submit" value="Search" name="search" <?php echo $disabled; ?>/>
    </form>
</body>
</html>

You could also do this by binding to the form's submit event - in jQuery it's

jQuery('#myForm').on('submit', ...)