views:

24

answers:

1

I'm trying to build something similar to Facebook's privacy selection menu, except without the 'custom' option. It will only list a few options such as 'show to all', 'show to friends only', or 'completely hidden'. Right now I'm thinking of using simple JavaScript to change a hidden input field to the new value they click on, so if they clicked on the division for 'show to friends only' it would change the corresponding field, say 'email_privacy', to 1. Is there a better way to do this or am I pretty much on track?

P.S. I am not planning on using a select element, I was planning on building a custom drop-down menu using CSS since select elements are so highly non-customizable. I'm doing it this way to save space, rather than having this massive selection menu at the right which takes up a bunch of space.

Note: I'm not really interested in using jQuery, that's just extra libraries and crap that I don't want to load. I can do it in JavaScript just as easily so I might as well use that.

A: 

It sounds like you're on the right track. If you're planing on doing a POST when the user clicks the submit button containing (amongst other things) the privacy value, then you'll need to pack it in the POST data somehow, and a hidden field is a way to do it.

Alternatively if you were interested in making use of jQuery (which I know you said you weren't but just putting it out there) you can perform asynchronous POST requests passing along with it arbitrary data, such as in this instance the privacy setting, without needing to 'copy' it into a hidden field.

Both options work just fine though.

Michael Shimmins