Strugling to put an onclick js funcation inside php

Hai folks,

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 :

alert('hai')

pls help :rolleyes:


<td>
  <img src="admin-icons/delete.png" alt="delete" onclick="alert('valid markup!');" />
</td>  

Hai anthony,
hmm, did not work

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 :

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/>";

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 :rofl: :smiley:

hai Anthony, one more doubt if you don’t mind, do that alert () function parameter must be rapped in double quotes?

Try it. :wink: