Click here to Skip to main content
15,888,020 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I want to know if it is possible to display an image in the textbox?
If yes then how to implement it in using javascript?

Thanks!
Archana
Posted

You can use css for this. Set a background-image.
HTML
<input type="text" style="background-image: url(/Content/Icons/16/address_book.png);"/>


If you want a small image at the left side (like a search icon for a search box) then add a no-repeat and some padding to make the text be placed beside the image. (in this example I've used a 16x16px image)

HTML
<input type="text" style="background-image: url(/Content/Icons/16/address_book.png); background-repeat: no-repeat;  padding-left: 16px;"/>


Now you will have a nice textbox with a background icon and the text will not be placed over the icon.
 
Share this answer
 
v2
Comments
archies_gall 24-Jul-12 7:38am    
How can i specify image height and width?
StianSandberg 24-Jul-12 7:41am    
Yes. You can use css3 "background-size: 10px 10px;" But this is css3 and is not compatible with old browsers. You should not scale images on client anyway.
So my suggestion is to create an image in the right size..

More info about background-size here: http://www.css3.info/preview/background-size/
archies_gall 24-Jul-12 13:57pm    
This is for simple text box.
What if i have below scenario:
Web page is divided into 4 frames. Each frame has a text box,image and button. When i click on button in frame1 then information about the frame no. and image should be displayed in the text box.
I am able to get the frame no. in text box but dont know how to display image in textbox on click of button using frames.

Thanks
 
Share this answer
 
Comments
StianSandberg 24-Jul-12 7:36am    
your first link is for windows forms.
your third link is not in the textbox, but aside.
And your second link is the same solution as mine..
_Amy 24-Jul-12 7:39am    
Ha-ha. Thanks. I din't tested that. Sorry..
Member 11160383 14-Nov-14 22:30pm    
how to upload image on text area as a application form

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