Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want to pass user submitted url as image source

Status
Not open for further replies.

blaiwesd

Programmer
Sep 8, 2006
5
US
Ok, here is my dilemma, I've been experimenting with forms in javascript, but have been unable to achieve anything productive.

I would like to have a form containing one text field in which the user types the url of an image, clicks submit, and the image appears on the page.

I can't figure out how to take the string variable and use it as an image source.

Please help, any code is appreciated. thanks
 
You could try something like:

Code:
<form action="" name="imageform" onsubmit="return false">
Type in the name of the image you wish to view: <input type="text" value="" name="imagename">
<input type="button" value="Get Image" onclick="document.getElementById('image').src = document.forms['imageform'].elements['imagename'].value;">
</form>
<img id="image" src="">

Lee
 
thanks man, thats just about what I was trying to achieve, but I was hoping that images could be displayed on a redirected page. Is this possible?
 
The code I provided is what you asked for. This should display the image on a separate page:

Code:
<form action="" name="imageform" onsubmit="this.action = this.elements['imagename'].value">
Type in the name of the image you wish to view: <input type="text" value="" name="imagename">
<input type="submit" value="Get Image">
</form>

I tried it in IE 6 and it worked fine. You might have to add a path yourself if the images are in a separate folder.

Lee
 
I had forgotten to ask for it, and what I meant by a redirected page, was, the user clicks submit, and it takes them to another page on the website, where in the body of the page, the image is displayed. not just a new window with the image in it.

Thanks for all the help so far, I really appreciate it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top