• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
creating HTML and PHP hyperlink text

#2
[eluser]pickupman[/eluser]
Its you may have one of the lines of code out of order.
Code:
<div id="container">
   <h1>Select a Faculty</h1><br>    
    &lt;?php
    foreach($faculties as $row){
     echo '<a class="faculty_'.$row-&gt;facultyID.'" href="'. $row-&gt;facultyID.'">';
     echo '<b>'.$row->facultyName.'</b><br/>';
     echo '<br/>';    
    }
    ?&gt;
    </a>
  </div>

If you are wanting to return an id on click, but not change the page, you will need to use javascript. Likely jQuery to attach to the click event. Then use a regular expression to get the id from the class string.

Code:
$("a[class^='faculty_']").click(function(event){
   var mystr = $(this).attr('class');
   var id = mystr.replace(/mystr/ig, 'faculty_');
   alert(id);
    event.preventDefault();
});

Didn't test javascript, but should be close enough.


Messages In This Thread
creating HTML and PHP hyperlink text - by El Forum - 12-10-2012, 05:02 AM
creating HTML and PHP hyperlink text - by El Forum - 12-10-2012, 07:08 AM
creating HTML and PHP hyperlink text - by El Forum - 12-10-2012, 08:07 AM
creating HTML and PHP hyperlink text - by El Forum - 12-10-2012, 05:05 PM
creating HTML and PHP hyperlink text - by El Forum - 12-10-2012, 08:35 PM
creating HTML and PHP hyperlink text - by El Forum - 12-11-2012, 10:50 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.