By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

PHP and the Document Object Model

nathj
Expert 100+
P: 938
Hi,

I'm currently working on a project that is making use of the DOM. This is great way to save time and code and generally make life easier. However, I have an issue that cannot seem to overcome.

I have a PHP page that deinfes a form in a disabled state. Then when the user clicks edit the controls are enabled. This is done with a call to a JS function that takes the ID of the form. Then using the elements array the disable state of each element is flipped to be what it is currently not - the value of the attirbute is inverted. This works fine. No problems there.

The trouble comes when I only want certain elements of the form to be enabled depending on the user access rights. My plan was to add an attribute to each form element and then check the value of this in the javascript as I could set that in the php depending on the access rights.

This leads to my question. How do I add a new attribute to the input elements in PHP so that they are available in the DOM?

My alternative is to pass a comma seprated list of input ID's to the JS function convert that to an array and then set the disabled status as I loop through the array. This would enable me to have different things sent over but it is not exactly future proof.

Many thanks
nathj
Dec 6 '07 #1
Share this Question
Share on Google+
2 Replies


pbmods
Expert 5K+
P: 5,821
Heya, Nathj.

If you're working with a static form, it probably makes the most sense to simply give each element an ID, then create a JavaScript array of 'permitted' IDs.

If you're working with a dynamic form, you might want to consider using AJAX or else to use pure JavaScript to build the entire form and have PHP generate that JavaScript.
Dec 23 '07 #2

nathj
Expert 100+
P: 938
Heya, Nathj.

If you're working with a static form, it probably makes the most sense to simply give each element an ID, then create a JavaScript array of 'permitted' IDs.

If you're working with a dynamic form, you might want to consider using AJAX or else to use pure JavaScript to build the entire form and have PHP generate that JavaScript.
Hi pbmods,

The static form with the array of permitted Id's was pretty much what I went for in the end.

Thanks for the reply though, it's nice to know I'm not the only one that came up with this solution.

Cheers
nathj
Dec 24 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.