javascript - Getting the id of the anchor tag which was clicked -
this list representation of data coming php database.the list fetched using foreach php loop , data inside achor tag populated accordingly.
<?php foreach($array $iterate):?> <div class="col-sm-3"> <div class="panel panel-default"> **<a onclick='thefunction();' id="hello" href="#mymodal" style="text-decoration:none;">** <div class="panel-heading"> <img src ="audi_sillhouete.jpg" style="height:100%; width:100%;"> <p id="10" style="position:absolute; top:10%; padding-left:5%; padding-right:15%;"><?php echo $iterate->test_name ?></p> </div> </a> </div> </div> <?php endforeach;?>
as can see here, inside anchor tag have href-ed modal box show message whenever user clicks on of link. there button in modal window take user different page. issue want pass value along url, cannot link next page defined in modal window specification part. came solution. thought of using id attribute of anchor tag, tried id attribute of anchor clicked using javascript.
<script type="text/javascript"> function thefunction() { var id = $('a', this).attr('id'); alert(id); }</script>
from wanted initialize php variable , use php variable pass value in href of modal window button. value getting in alert box 'undefined' reason. have tried possible combinations of this.
$('a',this).attr('id'); $this.id;
everything return 'undefined'.
reference-this code modal window part.
<div class="modal fade" id="mymodal" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">instructions</h4> </div> <div class="modal-body"> test commence. timer initiated after moment start test. may choose answer question, or leave empty. can attempt questions in order find suitable.<br><br>upon completion of test, click on "submit" see performance statistics.<br><br><br>good luck! </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">close</button> <a href="../test/pretest.php?test=<?php echo $testname?>" style="text-decoration:none;color:white;"><button type="button" class="btn btn-primary">continue</button></a> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div><!-- /.modal -->
Comments
Post a Comment