Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want remove image from my display page....i wrote the php code , but nothing happend...help pls

What I have tried:

PHP
<title>Display the Image


<center>
<table width="50%" border="1" cellpadding="5" cellspacing="5"><thead><tr><th>ID NO</th><th>USER NAME</th><th>IMAGE</th></tr></thead>
    // Function to handle image removal
function removeImage()
{
		
var as=document.getElementById('$image')
}
as.remove();
<tbody><tr><td>  </td><td>  </td><td>" width="100" height="100" alt="image">						
Remove Image
</td></tr></tbody></table>		
			

	
</center>
Posted
Updated 14-Nov-23 6:39am
v3
Comments
Richard MacCutchan 14-Nov-23 11:11am    
Where is the image tag, and where is the code that actually calls the remove function?
[no name] 14-Nov-23 12:06pm    
https://www.w3schools.com/jsref/prop_style_visibility.asp

The visibility property sets or returns whether an element should be visible.

The visibility property allows the author to show or hide an element. It is similar to the display property. However, the difference is that if you set display:none, it hides the entire element, while visibility:hidden means that the contents of the element will be invisible, but the element stays in its original position and size.

1 solution

Wow. So many things wrong in such a small amount of code. Reformatting what you posted so it's readable:
HTML
<title>Display the Image

<center>

<table width="50%" border="1" cellpadding="5" cellspacing="5">
    <thead>
        <tr>
            <th>ID NO</th>
            <th>USER NAME</th>
            <th>IMAGE</th>
        </tr>
    </thead>


    // Function to handle image removal
    function removeImage()
    {
        var as=document.getElementById('$image')
    }

    as.remove();

    <tbody>
        <tr>
            <td>  </td>
            <td>  </td>
            <td>" width="100" height="100" alt="image">Remove Image</td>
        </tr>
    </tbody>
</table>

</center>


First, that's not HTML. That's a badly formatted fragment of HTML. It's also not even correct as there is no html or body tags. The title tag is only valid inside a head tag, which you also do not have.

You have what I assume is a partially missing img tag, with width, height, and alt attributes that will be treated like text instead of HTML.

You have javascript code in the middle of a table, but not wrapped in a script tag. That's not going to work at all.

Your getElementById call isn't going to return anything because putting a $ character at the beginning of an ID doesn't work for ID values. YOu have to preface the ID with a # character to select by a tag ID. Further, you don't have any tags that specify any IDs at all!

To select a tag by an attribute value (id, alt, width, height are all attributes in HTML), you have to specify the attribute and value you're looking for inside square brackets in your selector specification:
JavaScript
var tags = document.querySelector('img[alt="image"]');

The call to querySelector will return a collection of ALL img tags that have an alt attribute, not just one tag.

Your call to getElementById will return the first tag it finds, not a collection. You have to know about the differences between a single object and a collection and handle what those functions return differently.

[EDIT - Things I forgot to type]
Your as variable goes out of scope, meaning it doesn't exist anymore, when execution leaves the curly braces where you defined as. Your call to remove will fail because as variable no longer exists.

And finally, where do you even call the removeImage function from? You've got nothing making that call, so nothing is going to happen.

I'm not fixing this for you because it's homework. If I do it for you, you learn nothing but dependence on others to fix your own mistakes.
 
Share this answer
 
v2
Comments
Andre Oosthuizen 14-Nov-23 12:42pm    
"So many things wrong in such a small amount of code. Reformatting what you posted so it's readable" should have earned +10 and not just my +5!
Maciej Los 15-Nov-23 12:32pm    
+5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900