| | |
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:
Solved Threads: 0
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 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
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)
function insertText() { //getElementById('camera').value=getElementById("captionPlaceHolder"); document.getElementById('camera').value = document.getElementById('captionElement').value; }
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
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 :
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.
Airshow
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.
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 javascript Syntax (Toggle Plain Text)
function handleImageClick(uid){ // whatever ... document.getElementById('imageID').value = uid; // whatever ... }
Airshow
50% of the solution lies in accurately describing the problem!
![]() |
Similar Threads
- Can I capture form input text & pass it to the following page (JavaScript / DHTML / AJAX)
- form input to text file - cant figure this one out (PHP)
- Changing the action of a Form with an Input Named Action (JavaScript / DHTML / AJAX)
- input text (JavaScript / DHTML / AJAX)
- Change Form action with Submit button? (PHP)
- Selecting all input text fields (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: onclick problem in IE, working in FF/other
- Next Thread: [ask] JQuery preventDefault is not working
| Thread Tools | Search this Thread |
Tag cloud for dom, element, form, html, javascript
actionlistener ajax ajaxcode ajaxhelp api array asp asp.net basic box c# cart cgi changeable checkbox code creat css data debugger decimal design developer development dom download dreamweaver editor element email epilepsy explorer external feedback files firefox flash form format forms frameworks getselection google gui guidancer gwt highlightedword html iframe include internet java javascript jquery jsfile jsp login maps math mp4 mysql news open oracle paging password paypal perl php post problem regex robot scroll search security session shopping singleton size synchronous tables testautomation textbox unicode upload url validation validator vb vb6 visual visualbasic vulnerability w3c web webbrowser website window xml






