0

I am making a live search where when user type in a search box, results start showing up inside a table. A <td> of this table should display the result as a text link.

I have this AJAX script:

success:function(res)
    {
      $("#patient_name_table tr").fadeOut(500);
      $.each( res, function( key, row ) {
              //alert(row['patient_name']);
              $("#after_tr_2").after("<tr><td>"+row['patient_name']+"</td></tr>");
            });
    },

Results are shown properly, but when I tried to add an <a href> to it like:

success:function(res)
    {
      $("#patient_name_table tr").fadeOut(500);
      $.each( res, function( key, row ) {
              //alert(row['patient_name']);
              $("#after_tr_2").after("<tr><td><a href='patients.php?patient='"+row['patient_name']+"></a></td></tr>");
            });
    },

I have the same exact row shown but clickable text is like hidden.

1 Answer 1

2

Just forget to close the a tag '> and remove the ' before the "+row Replace. To Show text insert row['patient_name'] into the <a></a> tags

 $("#after_tr_2").after("<tr><td><a href='patients.php?patient='"+row['patient_name']+"</a></td></tr>");

with

 $("#after_tr_2").after("<tr><td><a href='patients.php?patient="+row['patient_name']+"'>" + row['patient_name']  + "</a></td></tr>");

If the patient name is GoodPatient the html out put is

<tr><td><a href='patients.php?patient=GoodPatient'>GoodPatient</a></td></tr>

and this should be fine.

Sign up to request clarification or add additional context in comments.

6 Comments

No, still the same, I have the > in my code but some way it was missing here in my question
Kordi's answer is correct but he forgot the closing '' for the href attribute.
@Utkanos fixed it, in the moment you wrote your comment .. Thanks a lot for the note if I didn't get it!
Oh okay, I added the ' but still the same problem
@androidnation and you have to remove the one ' before the "+row. Updated my answer!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.