logo

Creating Temporary Fields in Web Forms

There are a few ways I've seen of displaying field-like inputs on the web without storing them in the submitted document, but I think what I'm about to describe is the easiest way of all.

Basically you don't give the field a name, but give it an ID instead. For example:

<input id="ToDo_tmp" type="text" />

In the browser this looks and acts like a real field. However, when you come to submit the form it isn't counted as a "Successful Control" and its name/value isn't sent to the server.

These kind of fields are really useful sometimes. As a simple example take the ToDo list form from the other week. As I mentioned then, the code added the given value to a set of hidden fields, all with the same name, which can be saved in a multi-value field.

Imagine we had a real field on our form called "ToDo" with "type="\hidden\"" in its HTML Attributes. This field is multi-value and separated by semi-colons. Using a clickable button, JavaScript and our temporary field we can add its values like so:

oFrm["ToDo"].value+=(document.getElementById("ToDo_tmp").value)+";"

Or, for you Prototype fans:

$("ToDo").value+=$F("ToDo_tmp")+";"

Obviously not a great example, but you get the idea, right? To add the temporary field you can use PassThru HTML and you can even give it a value using Computed Text. Note that this applies to all field types. Not just plain text ones.

Comments

  1. That's handy. I don't think I've used that particular exploit before. With the prevalence of operating on field id's, however, I wonder how long before some browser decides this is equivalent to a field name. Nice tip though.

    • avatar
    • Jake Howlett
    • Mon 26 Jun 2006 08:35 AM

    Jerry. As I understand it the browser should only submit the field to the server if the name is given. If a browser to send an id/value pair it's breaking the W3C guidelines.

  2. Isn't name a required attribute - meaning that this would cause a page to fail vailidation?

    • avatar
    • Jake Howlett
    • Mon 26 Jun 2006 10:13 AM

    Hi Peter. I just ran this page through the W3C validator and it didn't mention it.

  3. This is an awesome method to allow browser-only fields for UI functionality without cluttering up your document with 30 fields that have a "tmp_" prefix. Good stuff!

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Mon 26 Jun 2006

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content