Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Tuesday, April 26, 2016

What HTML element to use for holding hidden values

What HTML element to use for holding hidden values


In my application I have a need to keep some values hidden, for them to be later picked up by jQuery.

I have a following div for keeping map's data (after img is clicked I would like to show a map with 2 markers):

In order to do that I need to store 4 hidden values (1_lat, 1_long, 2_lat, 2_long), like:

What would the right hidden element be for storing such values? Label, p or something else?

Answer by scrappedcola for What HTML element to use for holding hidden values


You should probably use an input box of type hidden for this purpose:

  

You can then update this value with $("#1_lat").val("22.0")

Answer by T. Frick for What HTML element to use for holding hidden values


You can use the input type="hidden".
reference: w3schools

Answer by Christophe Maggi for What HTML element to use for holding hidden values


I suggest you always use INPUT for the hidden values.

Answer by Johnny for What HTML element to use for holding hidden values


in dreamweaver you can use it as gui drag and drop from the php toolbox on the right

Answer by Margaret Bloom for What HTML element to use for holding hidden values


Since it seems that you will only use those values client-side, i.e. you are not going to send them back to the server, it seems wrong to me to use an input element.

The comments already have two very good advice, here expanded.


Personally I would use data attributes if I needed per-element data (data that varies per element).

...
...

They can be accessed very easily.

function configureTheMap(map)  {      var lat1 = map.dataset.lat1;      var lat2 = map.dataset.lat2;         ...  }    ...    configureTheMap(document.getElementById('sampleMap'));  configureTheMap(document.getElementById('anotherSampleMap'));  

You should check browser compatibility though.

If the data was global I would simply generate a JavaScript object

var coordinates_config = {lat1 : 0.241, lat2 : 0.56};  

and use it accordingly

function configureTheMap(map)  {      var lat1 = coordinates_config.lat1;      var lat2 = coordinates_config.lat2;         ...  }  

You can generalize this method easily to be used for per-element data if data attributes are not supported by the browsers you are targeting.

In both cases, allow me to remember the importance of proper escaping when generating the markup/code.

Answer by Hearty for What HTML element to use for holding hidden values


There are a few alternatives as follow :

  1. element
  2. HTML5 Custom Data Attributes
  3. Custom non-visible data with data attributes


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.