Change form input text using Javascript/Dom

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Mar 2008
Posts: 4
Reputation: colerainescotty is an unknown quantity at this point 
Solved Threads: 0
colerainescotty colerainescotty is offline Offline
Newbie Poster

Change form input text using Javascript/Dom

 
0
  #1
Oct 22nd, 2009
Hi there, I am wanting to find out how to add text to a hidden field in a HTML form. I want to add text from an array, the array holds the information for the caption placeholder for the images.

Basically i have an image viewer which lets you scroll through images and they have a text caption below them telling what the images are. When the user clicks an image this brings up the form and hides the imageViewer. I want the caption of the image clicked to automatically be entered into the hidden field of the form when a user decides to choose a particular photo, so that it sends this to the server script for processing.

At present i have the function
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function insertText()
  2. {
  3. //getElementById('camera').value=getElementById("captionPlaceHolder");
  4. document.getElementById('camera').value = document.getElementById('captionElement').value;
  5. }
i have commented some out to try various things.

My form input box has an id="camera" and i was told to do something like this. Give the hidden element an id="someName"...then in the JS you can change the value of it by the usual way...
getElementById('someName').value=??? where ??? is the name of the camera the user has

I have been messing about now for hours and just can't get it. I really hope someone can help me out. Im new to this by the way

Thanks again
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 861
Reputation: Airshow is on a distinguished road 
Solved Threads: 122
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark
 
0
  #2
Oct 22nd, 2009
Scotty,

I have to ask why you might want to send image captions back to the server?

The reasons I ask are that :
  • Captions are not necessarily unique. In a typical gallery for example, you could have a whole string of images with the caption "Sports Day".
  • The server should have the means of enquiring (typically from a database) the caption for each image. It must have done this to serve the gallery in the first place.
It would therefore be more normal to address each image by a unique identifier (UID), this being the primary key (or a derivative of it) against which the image is stored in the database. Less typically, the UID might be the directory/file path in which the image is stored on the server.

There are various ways to do this. Personally I would arrange for the click associated with each image to pass the image's UID to the handler function as an argument. eg. onclick="handleImageClick(12345)" . The function would then be of the form
  1. function handleImageClick(uid){
  2. // whatever ...
  3. document.getElementById('imageID').value = uid;
  4. // whatever ...
  5. }

Airshow
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 4
Reputation: colerainescotty is an unknown quantity at this point 
Solved Threads: 0
colerainescotty colerainescotty is offline Offline
Newbie Poster
 
0
  #3
Oct 23rd, 2009
Thanks again,

Its part of a university assignment, its not a live website. solved!
Reply With Quote Quick reply to this message  
Reply

Tags
dom, element, form, html, javascript

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC