SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Strugling to put an onclick js funcation inside php

    Hai folks,

    php code :

    PHP Code:
    <td><img src='admin-icons/delete.png' alt='delete' /></img></td
    now when this image is clicked, i want to run the below js funcaiton :

    Code JavaScript:
    alert('hai')

    pls help

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <td>
      <img src="admin-icons/delete.png" alt="delete" onclick="alert('valid markup!');" />
    </td>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AnthonySterling View Post
    Code:
    <td>
      <img src="admin-icons/delete.png" alt="delete" onclick="alert('valid markup!');" />
    </td>
    Hai anthony,
    hmm, did not work
    Code:
    Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home2/mairfare/public_html/rent/demos/cpanel-property-processor.php on line 29
    * line 29 mean the line contain your code..

    here the complete code :

    PHP Code:
    echo "<table width='700' border='1'>";
      echo 
    "<tr><th>Manage</th><th>Delete</th><th>View Listing</th><th>Title</th><th>Type</th><th>City</th><th>Date</th></tr>"  
       
    ;
       

        while (
    $raw=mysql_fetch_array($result)){
        
           
    $pid=$raw['pid']; 
           echo 
    "<tr>
                     <td>" 
    "<a href='property-info-edit.php?pid=$pid'><img src='admin-icons/usermanager.png' alt='manage' /></img></a></td>
             
             <td><img src='admin-icons/delete.png' alt='manage' onclick='alert("
    valid markup!");' /></img></td>
                    
            <td>" 
    "<a href='browse-property.php?pid=$pid'><img src='admin-icons/view-listing.png' alt='manage' /></img></a></td>                
            <td>" 
    $raw['title'] . "</td>
            <td>" 
    $raw['type'] . "</td>
            <td>" 
    $raw['city'] . "</td>
            <td>" 
    $raw['dt'] . "</td>                                    
            </tr>"
    ;       
        
        }


    echo 
    "</table><br/><br/>"

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo "<table width='700' border='1'>"
      echo 
    "<tr><th>Manage</th><th>Delete</th><th>View Listing</th><th>Title</th><th>Type</th><th>City</th><th>Date</th></tr>"   
       

        

        while (
    $raw=mysql_fetch_array($result)){ 
         
           
    $pid=$raw['pid'];  
           echo 
    "<tr> 
                     <td>" 
    "<a href='property-info-edit.php?pid=$pid'><img src='admin-icons/usermanager.png' alt='manage' /></img></a></td> 
              
             <td><img src='admin-icons/delete.png' alt='manage' onclick='alert(\"valid markup!\");' /></img></td> 
                     
            <td>" 
    "<a href='browse-property.php?pid=$pid'><img src='admin-icons/view-listing.png' alt='manage' /></img></a></td>                 
            <td>" 
    $raw['title'] . "</td> 
            <td>" 
    $raw['type'] . "</td> 
            <td>" 
    $raw['city'] . "</td> 
            <td>" 
    $raw['dt'] . "</td>                                     
            </tr>"
    ;        
         
        } 


    echo 
    "</table><br/><br/>"
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AnthonySterling View Post
    PHP Code:
    echo "<table width='700' border='1'>"
      echo 
    "<tr><th>Manage</th><th>Delete</th><th>View Listing</th><th>Title</th><th>Type</th><th>City</th><th>Date</th></tr>"   
       

        

        while (
    $raw=mysql_fetch_array($result)){ 
         
           
    $pid=$raw['pid'];  
           echo 
    "<tr> 
                     <td>" 
    "<a href='property-info-edit.php?pid=$pid'><img src='admin-icons/usermanager.png' alt='manage' /></img></a></td> 
              
             <td><img src='admin-icons/delete.png' alt='manage' onclick='alert(\"valid markup!\");' /></img></td> 
                     
            <td>" 
    "<a href='browse-property.php?pid=$pid'><img src='admin-icons/view-listing.png' alt='manage' /></img></a></td>                 
            <td>" 
    $raw['title'] . "</td> 
            <td>" 
    $raw['type'] . "</td> 
            <td>" 
    $raw['city'] . "</td> 
            <td>" 
    $raw['dt'] . "</td>                                     
            </tr>"
    ;        
         
        } 


    echo 
    "</table><br/><br/>"

    working

  6. #6
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    hai Anthony, one more doubt if you don't mind, do that alert () function parameter must be rapped in double quotes?

  7. #7
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Try it.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •