jqueryjqmodal

How to make this function work on an onclick event


I have this Javascript:

<script language="javascript" type="text/javascript">
$().ready(function() {
$('#ex2').jqm({ajax: 'view.php?id=<?=$objResult["id"];?>', trigger: 'a.ex2trigger'});
});
</script>

That requires this HTML:

<a href="#" class="ex2trigger">
View
<div class="jqmWindow" id="ex2">
Please wait... <img src="inc/busy.gif" alt="loading" />
</div>

How would I integrate this so it works on a table <tr onclick> event? So when you click a row it brings up the corresponding view.php?id=

Thanks in advance.


Solution

  • You would attach an event handler to the table monitoring the clicks on the rows. You then would get the index of that row and pass it to your function.

    $("table").on('click','tr',function(){
         $('#ex2').jqm({ajax:'view.php?id='+$(this).index(),trigger:'a.ex2trigger'});
    });