2

What is a common way to pass data for formula fields, to specify a quantifier. I would currently do as follows:

<input type="text" name="myfield" class="inputfieldstyle quantified" id="q_12" value="foo" />

where q_12 is generic.

But there some inherent problems with the approach:

  • What if i want to give it an id for some js/css reason?
  • q_12 is not easy to read with js: var quant = parseInt(element.id.split('_').pop())
  • id is not made for passing values

How should I handle this? Is there a common way? Is there a way suggested by w3c?

James Wiseman
  • 29,946
  • 17
  • 95
  • 158
helle
  • 11,183
  • 9
  • 56
  • 83

2 Answers2

4

A good and simple way is to use hidden fields :

<input type="hidden" name="myname" value="my_value" id="my_id">
Guillaume Lebourgeois
  • 3,796
  • 1
  • 20
  • 23
  • You could also use an unique one, and serialize a string into the value attribute. Example : `myid;value|myotherid;value2|myotherotherid;value3` etc... – Guillaume Lebourgeois Aug 02 '10 at 15:20
  • i thought more of some creative innovative approach :-(. i don't want to give my bounty to a solution i want to avoid (don't take that personally!!!)... well, my resolution so far is, that i pass a json object to my JS which holds IDs (of input fields) and corresponding quantifiers. then i iterate these items triggered by an event .... also not a very cool solution, i think. – helle Aug 04 '10 at 13:39
  • but maybe there is no such resolution ... so far :-) – helle Aug 04 '10 at 13:40
  • That's a common issue, and i wouldn't know how to do that in an elegant way. You may get some ideas with Prototype to deal with forms, here for example : http://www.prototypejs.org/api/form – Guillaume Lebourgeois Aug 04 '10 at 14:34
2

You could extend the hidden fields idea of Guillaume Lebourgeois. If you're worried about having two inputs for each, you could always adopt the "data-" attribute approach as detailed in the following link: http://ejohn.org/blog/html-5-data-attributes/

<input type="hidden" name="myname" id="my_id" 
       data-myData1="somedata" data-myData2="somemoredata" value="" >

and then use getAttribute to return the value (http://www.devguru.com/technologies/javascript/17457.asp):

document.getElementbyId("my_id").getAttribute("data-myData1")       
document.getElementbyId("my_id").getAttribute("data-myData2")

Or if you are using jQuery:

$("#my_id").attr("data-myData1")    

Of course, you would have to roll this up into the value before passing across pages, but its still a possiblity.

James Wiseman
  • 29,946
  • 17
  • 95
  • 158