Adding hidden fields to a Form

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.


No Responses to “Adding hidden fields to a Form”  

  1. No Comments

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



Calendar

June 2005
M T W T F S S
    Jul »
 12345
6789101112
13141516171819
20212223242526
27282930  

Follow me

twitter flickr LinkedIn feed

Subscribe by email

Enter your email address:

Archives


Categories

Tag Cloud


Listening