| | |
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 |
.net 2.0 6 action adobereader ajax asp asp.net basic box browser c# c++ cakephp calendar cart cgi checkbox close code codeinjection codes column copy createrange() css current development directrobot dom element email enter explorer feedback firefox flash focus form forms functiontesting google gxt head html htmlform ie8 iframe images internet java javascript jlabel jquery jsp logfiles login loop masterpage math microsoft mysql news object open paypal php post problem programming safari scale scriptlets select shopping source static tag test treeview trouble unicode upload validation variables vb video visual visualbasic6 visualization vulnerability w3c web window windowofwords windowsxp wpf wysiwyg xml zend






