473,385 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to get text input to be used as a reference to an image src

Jason Moyes
I've been looking for a reference to my situation for two days and i can't find any that are relevant enough.

I'm trying to accept text as a URL for an image source.
I then display that image in a form with the use of a <button type=button onclick=codeThatGeneratesImage > type thing.

Expand|Select|Wrap|Line Numbers
  1.             function addImageToForm(formID) {
  2.                 //get a reference to the form
  3.                 var formElement = document.getElementById(formID);
  4.                 //get a reference to the element that contains the url
  5.                 var elementWithImageURL = document.getElementbyId("imageURLInput");
  6.                 //get URL entered
  7.                 var imageURL = elementWithImageURL.getAttribute("value");
  8.                 //create image element
  9. ----------------------------------------------------------------------------------
  10.                 var newImage = document.createElement("img");
  11.                 //reference the source using the url
  12.                 newImage.setAttribute("src", imageURL);
  13.                 newImage.setAttribute("name", "newImage");
  14.                 //append the image to form
  15.                 formElement.appendChild(newImage);
  16.             }
  17.  
i know that the bottom half works because i tried it with just a reference to an image directly and it worked.

i can't figure out why most of the top part isnt working.

any help would be much appreciated :)
Sep 29 '10 #1
2 1252
RamananKalirajan
608 512MB
Expand|Select|Wrap|Line Numbers
  1.  var imageURL = elementWithImageURL.getAttribute("value"); 
replace this line with

Expand|Select|Wrap|Line Numbers
  1.  var imageURL = elementWithImageURL.getAttribute("src");
Thanks and Regards
Ramanan Kalirajan
Sep 30 '10 #2
Interesting. i gave it a try and it didn't work.

i want that line of code to get what the user has written.

I'm kinda new to javascript but elementWithImageURL
is a reference to my input element and as far as i know it doesn't have a src attribute.

thanks for the reply tho
any more ideas?
Sep 30 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jawahar Rajan | last post by:
All, I am using a few Input type of "Image" instead of a classic submit button in a form to achieve various tasks for example image1 - add user image2 - modify user image3 - delete user...
2
by: Kai Grossjohann | last post by:
I would like to put a text input field (in the sense of <input type="text">) and an image next to each other, where I know the size in pixels of the image, and I know the total width in em. I...
1
by: addi | last post by:
All, I need some help with replacing standard Input buttons with image files. Currently, my code is as follows: <td colspan="2" align="left"> <input type="submit" name="cancel" style="COLOR:...
2
by: X l e c t r i c | last post by:
Hi, I'm trying to put the last URL visited to a text input using history.previous for WebTV (because I can't get document.referrer to work with WebTV) and document.referrer for PC. This is for...
2
by: Mr.Clean | last post by:
If I have an Input of type image, it is not listed in the Forms elements when walking to DOM using MSHTML. Is this expected behaviour and how would I get the image input to submit the form NOT...
2
by: Offm | last post by:
I was trying to make some experiences with javascript , making a div response to a text input but cannot say what am doing bad so if anyone could help with the script, many Thanks the script...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
2
by: troberts | last post by:
Hi What I'm trying to achieve is a watermark on a search box (text input). I've got it working fine (it displays an image, onfocus it shows no image) but when the user writes something then clicks...
2
by: makunta | last post by:
I have coded a web form and styled it with css. It can be seen here: http://www.exmhosting.com/ The form is the small login one situated top right of the webpage. I have styled the text input...
0
by: pazazuzu | last post by:
Hi everyone, I currently have an assignment which I am almost done with but am having problems trying to figure out how to integrate a string function search. I have a text box called...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.