I have a click function that launches a modal window. Inside of the modal window I load modal_window.php. The click function look like this:
$('a#testmodal').click(function(e){
<? $id = $_GET['id']; ?>
varid = <? echo $id; ?>;
$.get('modal_window.php?id=' + varid, function(data){
modal.open({content: data});});
e.preventDefault();
});
And the link that I'm using to trigger it looks like this:
<a id="testmodal" href="modal_2.php?id=5">Test</a>
The strange thing is when I click on the link the first time nothing happens. However when I click on it the second time everything works as it should. The reason for this seems to be that the jquery piece of my code runs the first time before the php variable $id is set (the jquery section runs and then the php section runs). Then when I click on the link the second time (the php variable $id within the click function is set at this point) everything works perfectly.
So my question is is there a different way to pass a variable from my link to my click function that does not depend on php. Something like this:
<a id="testmodal" href="" var id ="5">Test</a>