From a simple html page, the user hits a button that says "Add Problem".

With that "click" a jQuery dialog pops up with a table that is "hidden" on the original page (display: none).

The user enters a "number" (icd-9 code for those of you familiar with medical codes) into an input field on the jQuery dialog.

When the user clicks a button the .dialog, the number is read, trimmed and sent to the first part of an if/else.

If the number is <3 characters, a message is put up in a div that says "This is not a valid icd-9 code".

(If it WERE valid, I'd do an .ajax call to see if there was a corresponding icd-9, if not give a message "No icd-9" or give the icd-9 code and the icd-9 text)

All of the first parts work fine, except that after putting up the "error" message, the user is immediately (I can barely see the message - I put up an alert to stop the flow and confirmed the message is there) taken back to the original html page, NOT the .dialog.

Here is the code in question:

```
$("#findbuttonicd9").click(function() {

    varicd9 = document.getElementById('icd9input').value;
    varicd9 = varicd9.trim();

    if (varicd9.length < 3)
       {
        document.getElementById("listicd9").innerHTML = varicd9 + "is not a valid ICD-9 Code";
        return;
       }
         else
       {$.ajax({
                type: "POST",
                url: readicd9backend.php,
                data: {icd9: varicd},
                dataType : 'json', 
                              success: function(result)
                                       {
                                        $("#div1").html("");
                                        if(result.length >= 1)
                                           {
                                            var output = "<table width='500px' class = 'findtable'>";
                                           $.each(result, function(index, value)
                                                 { output += "<tr><td id='icd9' width='50px'>" + value.icd9codedot +
                                                             "</td><td width='250px' style='text-align:left'>" + value.icd9long +
                                                             "</td></tr>";
                                             });
                                         output += "</table>";
                                         $("#listicd9").html(output);
                                     }
                                      else
                                     {$("#listicd9").html("No matches");}
              },
              error : function(e) { ("#listicd9").html('Database access error'); }
            });            
       }
});

```

I've tried to add a "retun" (as you see above) and done it without the "return" and it always brings me back to the original html page.

This problem of "flow control" is a new one for me, so I'd appreciate any help, even just a reference so I can try to hack through this myself.

And again, I thank you all very much.

Edits:
Here is the click function;

```
$("#addproblementerbutton").click(function() {
 $(function() {  $( "#addproblemtable" ).dialog({
                                                height: 550,
                                                width: 600,
                                                modal: true
                                                });
               });
});

```

Here is the whole table:

```
<!--start of hidden add problem table-->
<div id="addproblemtable" style="display:none" title="Add a Problem"><!--start of add problem div/table-->
<form id="addproblem">
<table id="addproblem" class="addproblemtable">
  <tr>
    <td style="width:200px; text-align:right;">ICD-9:</td>
    <td><input id="icd9input" type="text"></td>
    <td><button id="findbuttonicd9">FIND ICD-9</button></td>
  </tr>
  <tr>
    <td style="width:200px; text-align:right;">Problem:</td>
    <td><input id="problem" type="text"></td>
    <td><button id="findbuttontext">FIND TEXT</button></td>
  </tr>
  <tr>
    <td colspan="3">
      <div id = "listicd9" style="width:100%; height:200px; overflow-y:scroll; margin-top:10px; margin-bottom:10px; background-color:#F1E2FE">
      </div>
    </td>
  </tr>
  <tr>
    <td style="width:200px; text-align:right;">Date Noted:</td>
    <td><input id="dateonset" type="text"></td>
    <td></td>
  </tr>
  <tr>
    <td style="width:200px; text-align:right;">Date Entered:</td>
    <td><input id="dateentry" type="text"></td>
    <td></td>
  </tr>
  <tr>
    <td colspan="3">
      <input type="radio" id="active" name="status" value="Active" checked="checked" />
      <label class="styleradiobutton"  for="active">Active</label></input>
      <input type="radio" id="inactive" name="status" value="Inactive" />
      <label class="styleradiobutton" for="inactive">Inactive</label></input>
    </td>
  </tr>
  <tr>
    <td colspan="3" style="width:200px; text-align:center;">
      <input id="resetbutton" type="reset" value="RESET" class="formbutton"><!--reset the form-->
      <input id="addproblemsubmitbutton" type="button" value="ADD" class="formbutton"></td>
  </tr><!--add a problem button-->
  <tr>
    <td><div id=listicd9></div></td>
  </tr>
</table>
</form>
</div><!--end of add problem div/table-->

```

Here is the row from the .dialog table that you click on to start the if/else/ajax

```
  <tr>
    <td style="width:200px; text-align:right;">ICD-9:</td>
    <td><input id="icd9input" type="text"></td>
    <td><button id="findbuttonicd9">FIND ICD-9</button></td>
  </tr>

```

PS - I haven't completed the .ajax call because I couldn't get past the first if/else in debugging. Still working on that.

Thanks!