Today, I've had the problem to dynamically add additional informations to html forms. Not being an expert of JavaScript I thought it was very easy. But after trying to code something like this:
... var form = document.forms['myForm']; form.myHiddenField = new Hidden(); form.myHiddenField.value=myValue; ...
I discovered that it's not so easy. I also didn't find anything on google. I also looked-up on JGuru, but I just find this.
But I didn't find it satisfactory, because I don't want to remember to add divs to my forms. Here's my solution (that I added to JGuru)
... var form = document.forms['myForm']; var el = document.createElement("input"); el.type = "hidden"; el.name = "myHiddenField"; el.value = "myValue"; form.appendChild(el); ...
I've tested it with IE6, Firefox 1.0.2, Opera 7.54, but it shold work on any browser.
Search
Archives
Categories
- Android (3)
- Apple (26)
- Books (7)
- Eclipse (14)
- Errors (3)
- Firefox (7)
- Git (2)
- Hardware (16)
- Horror Code (8)
- Internet (18)
- Java (98)
- JavaScript (9)
- Life, universe and everything (45)
- Lifehacks (25)
- Linux (50)
- Opinions (25)
- OSX (4)
- Python (1)
- Software (27)
- Speeches and Conferences (8)
- Unix (3)
- Web (21)
- Windows (19)
Tag Cloud
Android apple architecture Bash colors configuration CSS Development Düsseldorf Eclipse germany Git Google Hardware hdr How-To Java JAXB job junit Karmic Linux MacBook music night Open Source Opinion oracle OSX patterns Pitfalls Practices Resume Security Software Suspend TDD Testing tip tonemapped Tricks Ubuntu video Web XML
WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.
Blog License
Blogs I like
Books on the desk
Friends' Blogs
- Antonio Terreno & Valter Bernardini
- Bruno Bossola
- Daniele Galluccio
- Domenico Ventura
- Ed Schepis
- Fabrizio Gianneschi
- Luca Grulla
- Luigi Zanderighi
- Marcello Teodori
- Mida Boghetich
- Muralidharan Chandrasekaran
- Piero Ricca
- Renzo Borgatti
- Simone Bordet
- Simone Bruno
- Uberto Barbini
- Valvolog
- Webtide blogs (Greg Wilkins & Jan Bartel)
Links




















No Responses to “Adding hidden fields to a Form”
Please Wait
Leave a Reply